title: Mocking Scala void function using Mockito
body: <p>I found a few answers for this but nothing is working for me. </p>
  
  <p>Trying to mock Apache Shiro Subject interface login method which returns void.</p>
  
  <p>Interface:</p>
  
  <pre><code>    void login(AuthenticationToken token) throws AuthenticationException;
  </code></pre>
  
  <p>I have tried :</p>
  
  <pre><code>   #1
    val subject = mock[Subject]
    doNothing().when(subject).login(new UsernamePasswordToken())
  
     #2
    val subject = mock[Subject]
    doNothing().when(subject).login(any[UsernamePasswordToken])
  
     #3
    when(subject.login(any[UsernamePasswordToken])).thenAnswer(new Answer[Void]() {
        override def answer(invocation: InvocationOnMock): Void = {
         null:Void
        }
  </code></pre>
  
  <p>I keep getting NullPointerException on login. My goal is test around the login method and test some success cases along with some failure cases where this method throws an exception.</p>