Ok this is weird. Mockito, Java, on windows.
when(mongoTemplate.findAndModify(any(Query.class), any(Update.class), any(FindAndModifyOptions.class), eq(Task.class)))
.thenReturn(t1)
.thenReturn(t2);
Now if I run this in debug mode it works fine. But if I put a break point on the when, and single step it fails.
The error in IntelliJ is
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Task cannot be returned by toString()
toString() should return String
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
So this is possibly some interaction with IntelliJ wanting to "toString()" the result while single stepping. Maybe Mockito needs to catch and fallback on toString on OngoingStubbing?