title: MOCKITO - Change the exception thrown based on number of times the method is called
body: <p>I want to throw a specific exception for the first 5 times the method is executed. Afterwards, I want to throw another exception.</p>
  
  <p>Ideally, I have this code snippet, which obviously doesn't work</p>
  
  <pre><code>int count = 0;
  int max = 5;
  
  @Test
  public void myTest(){
     ...
     doThrow(count++ &lt; max ? myException1 : myException2).when(myClass).myMethod()
     ...
  }
  </code></pre>
  
  <p>How can I make it work?</p>