title: With Mockito, how to stub a method with return type void which throws an exception when a certain argument is passed?
body: <p>Here is the principal <strong>Mockito</strong> documentation for <a href="http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html#5" rel="noreferrer">stubbing void methods with exceptions</a>. However, the example in the Mockito doc stubs a <strong>parameterless</strong> method. <strong>What if the method has parameters</strong> and the method throws an <em>Exception</em> if the a parameter does not fulfills the contract?</p>
  
  <p>So for the following class...</p>
  
  <pre><code>public class UserAccountManager {    
     /**
      * @throws Exception if user with provided username already exists
      */
      public void createAccount(User user) throws Exception {
          // db access code ...
      }
  }
  </code></pre>
  
  <p>... how can <strong>UserAccountManager.createAccount be mocked</strong> with <strong>Mockito</strong> so that it <strong>throws an Exception</strong> if a <strong>certain User object is passed</strong> as an argument to the method?</p>