Created
October 2, 2019 12:14
-
-
Save Opalo/e5b2ede6fec174a2426f95fdad0a0a51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes([ | |
@Grab(group='org.mongodb', module='mongo-java-driver', version='3.11.0'), | |
@Grab(group='org.spockframework', module='spock-core', version='1.3-groovy-2.5'), | |
@Grab(group='cglib', module='cglib-nodep', version='3.2.10'), | |
]) | |
import org.bson.types.ObjectId | |
import spock.lang.Specification | |
import spock.lang.Subject | |
import spock.lang.Shared | |
class WhateverSpec extends Specification { | |
@Shared | |
@Subject | |
def mapper = new MsgMapper() | |
def 'should map IDs properly'() { | |
given: | |
def ids = [ | |
new MsgId(id: new ObjectId('1' * 24)), | |
new MsgId(id: new ObjectId('2' * 24)), | |
] | |
and: | |
def longMsg = Stub(LongMsg) | |
longMsg.getPartsIds() >> ids | |
when: | |
def mapped = mapper.map(longMsg.partsIds) | |
then: | |
mapped*.id == ids*.id | |
} | |
} | |
class MsgId { | |
ObjectId id | |
String toString() { | |
id.toString() | |
} | |
} | |
class LongMsg { | |
String[] parts | |
String[] partsIds | |
} | |
class MsgMapper { | |
List<MsgId> map(String[] rawIds) { | |
rawIds.collect { new MsgId(id: new ObjectId(it)) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment