0
インタフェースを含むこのJavaコードがあります。インタフェース付きモックforループ
ILocation<ILocation> contactLocations = fileSystem.getContactLocations();
for (ILocation location : contactLocations) {
location.getType();
...
}
public interface ILocation{
String getName();
...
}
public interface ILocationS<T extends ILocation> extends IListCollectionWrapper<T> {
...
}
public abstract interface IListCollectionWrapper<E>extends ICollectionWrapper<E>{
public abstract List<E> getAsList();
}
ILocation<ILocation> contactLocations = fileSystem.getContactLocations();
for (ILocation locations : contactLocations) {
...
}
私はMockitoを使用して、forループの内容をテストしようとします。
Iterator<ILocation> mockIterator = mock(Iterator.class);
Mockito.when(locations.iterator()).thenReturn(mockIterator);
Mockito.when(mockIterator.next()).thenReturn(location);
Mockito.when(location.getType()).thenReturn("test");
私はあなたが適切にイテレータの他の重要な方法、hasNext
を嘲笑していないループ
独自のイテレータを作成しましたか?もしそうなら、あなたはそのコードを共有することができますか?そうでなければ、適切な 'ILocation'オブジェクトを返すために' fileSystem.getContactLocations() 'をモックして、イテレータをモックする必要はありませんか? – FriedSaucePots