Back to Error Prone

MockitoUsage

docs/bugpattern/MockitoUsage.md

2.49.0546 B
Original Source

Calls to Mockito.when should always be accompanied by a call to a method like thenReturn.

java
when(mock.get()).thenReturn(answer); // correct
when(mock.get())                     // oops!

Similarly, calls to Mockito.verify should call the verified method outside the call to verify.

java
verify(mock).execute(); // correct
verify(mock.execute()); // oops!

For more information, see the Mockito documentation.