I'm using mockito spy with this code:
Mockito.doAnswer(new Answer() {
Object answer(InvocationOnMock invocation) {
ImagesSorter mock = (ImagesSorter) invocation.getMock();
Object[] args = invocation.getArguments();
return mock.sortImages((List<Image>) args[0], (UserInfo) args[1],
fakeNowDate);
}
}).when(imagesSorterSpy).sortImages(imagesAsInsertionOrder, user);
And I see the answer() is called eagerly when the struct is:
when(spy.method())./*...*/.
but it's lazy evaluation when the struct is:
/*...*/.when(spy).method()
Shouldn't it be vise versa? Meaning /*...*/.when(spy).method()
is eager versus when(spy.method())./*...*/.
is lazy? Like do..while loop
?
I couldn't find documentation for that