I have code something like this:
public void testMe(List<SomeItem> someList) {
someList.forEach(someItem -> {
SomeItem newItem = someService.createModifiedVersion(someItem);
someService.doSomethingWith(newItem);
someService.doMoreWith(newItem, someItem);
}
I am having hard time to write test with when
and then verify
as I have to mock createModifiedVersion
with a loop. Right now I have something like this:
when(someService.createModifiedVersion(Mokito.any(SomeItem.class)))
.thenReturn(someNewItem1)
.thenReturn(someNewItem2)
.thenReturn(someNewItem3);
Which doesn't ensure someNewItem<N>
will be return for nth someItem
from someItemList
.
What will be best way to test in this case if I want to verify for all list items
verify(someService).doSomethingWith(someNewItem<N>);
verify(someService).doMoreWith(someNewItem<N>, oldItem<N>);
Note: represent nth element of the list
Any suggestion?
Update I guess I am asking how I can verify doMoreWith()
is called with newItem
and someItem
as that is in loop.