title: Error: a *different* void method cannot be stubbed with a return value
body: <p>When stubbing <code>ClassOne.methodOne</code>, I'm getting the following error message about stubbing a void method with a return value, even though <code>ClassOne.methodOne</code> is not void. The error seems to pertain to <code>ClassTwo.methodTwo</code>, even though I'm stubbing <code>ClassOne.methodOne</code>.</p>
  
  <pre><code>org.mockito.exceptions.base.MockitoException: 
  `'methodTwo'` is a *void method* and it *cannot* be stubbed with a *return value*!
  Voids are usually stubbed with Throwables:
      doThrow(exception).when(mock).someVoidMethod();
  ***
  
  If you're unsure why you're getting above error read on.
  Due to the nature of the syntax above problem might occur because:
  1. The method you are trying to stub is *overloaded*. Make sure you are calling
     the right overloaded version.
  2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not
     verify/stub final methods.
  3. A spy is stubbed using `when(spy.foo()).then()` syntax. It is safer to stub
     spies with `doReturn|Throw()` family of methods. More in javadocs for
     Mockito.spy() method.
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>public class ClassOne {
    private ClassTwo classTwo;
  
    public boolean methodOne() {
      classTwo.methodTwo();
      return true;
    }
  }
  </code></pre>
  
  <p>My test:</p>
  
  <pre><code>when(classOne.methodOne("some string")).thenReturn(true);
  </code></pre>
  
  <p>Why is this happening, and how do I fix it?</p>