title: Simulate first call fails, second call succeeds
body: <p>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.</p>
  
  <pre><code>for(int i = 1; i &lt; 3; i++) {
    String ret = myMock.doTheCall();
  
    if("Success".equals(ret)) {
      log.write("success");
    } else if ( i &lt; 3 ) {
      log.write("failed, but I'll try again. attempt: " + i);
    } else {
      throw new FailedThreeTimesException();
    }
  }
  </code></pre>
  
  <p>I can setup the success test with:</p>
  
  <pre><code>Mockito.when(myMock).doTheCall().thenReturn("Success");
  </code></pre>
  
  <p>And the failure test with:</p>
  
  <pre><code>Mockito.when(myMock).doTheCall().thenReturn("you failed");
  </code></pre>
  
  <p>But how can I test that if it fails once (or twice) then succeeds, it's fine?</p>