Попытка выяснить, почему Спок, похоже, не распознает вызов метода (объекта Mocked) как вызов. Посмотрел документы (http://spockframework.org/spock/docs/1.1-rc-3/all_in_one.html#_mocking) и не смог разобраться.
Вот глупая версия кода:
class VmExportTaskSplitter implements TaskSplitter<Export> {
@Inject
AssetServiceClient assetServiceClient
@Override
int splitAndSend(Export export) {
Map batch = [:]
Map tags = [:]
if (true) {
println('test')
batch = assetServiceClient.getAssetIdBatch(export.containerUuid,
export.userUuid, (String) batch.scrollId, tags)
print('batch: ')
println(batch)
}
return 1
}
}
А теперь тест:
class VmExportTaskSplitterSpecification extends Specification{
def "tags should be parsed correctly"(){
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClientImpl)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
Map map1 = [assetIds:["1","2","3","4","5"],scrollId:null]
client.getAssetIdBatch(_ as String,_ as String, null, _ as Map) >> map1
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map)
}
}
Вот раздражающая часть: обе строки по обе стороны от вызова assetServiceClient.getAssetIdBatch
напечатаны. Но Спок утверждает, что никаких призывов вообще нет ...
Using logging directory: './logs'
Using log file prefix: ''
test
batch: [assetIds:[1, 2, 3, 4, 5], scrollId:null]
Too few invocations for:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
Unmatched invocations (ordered by similarity):
None