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;
The shortest way to write what you want is
when(myMock.doTheCall()).thenReturn("Success", "you failed");
When you supply mutiple arguments to thenReturn
like this, each argument will be used at most once, except for the very last argument, which is used as many times as necessary. For example, in this case, if you make the call 4 times, you'll get "Success", "you failed", "you failed", "you failed".