0
考慮DynamoDB's QueryApi
。通過對爲什麼在這種情況下BDDMockito不能解析類型?
Iterable<Item>
一系列的(?不幸的)箍,
ItemCollection<QueryOutcome>>
最後等於我知道這是因爲我可以做的:
public PuppyDog getPuppy(final String personGuid, final String name) {
final QuerySpec spec = new QuerySpec()
.withKeyConditionExpression("#d = :guid and #n = :name")
.withNameMap(new NameMap().with("#d", "guid").with("#n", "name"))
.withValueMap(new ValueMap().withString(":guid", personGuid).withString(":name", name));
return getDog(index.query(spec));
}
private PuppyDog getDog(final Iterable<Item> itemCollection) {
// http://stackoverflow.com/questions/23932061/convert-iterable-to-stream-using-java-8-jdk
return StreamSupport.stream(itemCollection.spliterator(), false)
.map(this::createDogFor)
// it would be a little weird to find more than 1, but not sure what to do if so.
.findAny().orElse(new PuppyDog());
}
但是,當我嘗試寫在Mockito中使用BDDMockito進行測試:
@Test
public void canGetPuppyDogByPersonGuidAndName() {
final PuppyDog dawg = getPuppyDog();
final ArgumentCaptor<QuerySpec> captor = ArgumentCaptor.forClass(QuerySpec.class);
final ItemCollection<QueryOutcome> items = mock(ItemCollection.class);
given(query.query(captor.capture())).willReturn(items);
}
當我嘗試使items
爲Iterable
時,編譯器發出抱怨。
爲什麼dis?