I want to use Mockito to test the (simplified) code below. I don\'t know how to tell Mockito to fail the first time, then succeed the second time.
for(int i = 1;
I have a different situation, I wanted to mock a void function for the first call and run it normally at the second call.
void
This works for me:
Mockito.doThrow(new RuntimeException("random runtime exception")) .doCallRealMethod() .when(spy).someMethod(Mockito.any());