title: Calling Mockito.when multiple times on same object?
body: <p>When trying to use Mockito with Spring, by creating the Mock object via a bean declaration...</p>
  
  <pre><code>&lt;bean id="accountMapper" class="org.mockito.Mockito" factory-method="mock"&gt; 
      &lt;constructor-arg value="org.example.persistence.mybatis.mappers.AccountMapper" /&gt; 
  &lt;/bean&gt;     
  </code></pre>
  
  <p>...I found some strange behavior when calling Mockito.when multiple times without reseting the Mock object, for example:</p>
  
  <pre><code>Mockito.when(this.accountMapper.createBadGrammarException()).thenThrow(new BadSqlGrammarException("Bla", null, new SQLException()));
  </code></pre>
  
  <p>As soon as this code (the "Mockito.when") is called multiple time during the test (on the same mock), the tests fails with an error (BadSqlGrammerException even if this exception was what was actually expected - I do get a failure if I don't throw the exception, and throwing it manually works fine). Is this expected behavior? <a href="http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#17" rel="noreferrer">Mockito</a> seems to suggest creating a new mock every time, which would mean creating the DAO for each method...?</p>
  
  <p>What exactly happens when I call the Mockito.when method two times? How should the mock react? Replace the behavior? Ignore it? Unfortunately most searches only yield results for how to return different results for multiple calls to the method itself, but not what is to be expected for multiple calls to Mockito.when...</p>
  
  <p>I'm simply trying to understand Mockito and best practices here, because going with something just because it SEEMS to works seems to be a bad idea...</p>