title: Throwing exceptions from Mockito mock
body: <p>Something tells me I'm doing something wrong...it shouldn't be this hard.</p>
  
  <p>I have a class that relies on some inner class. I'm creating that inner through a protected method so that I can override that in a test to provide a mock. I understand that to get a Mockito mock object to throw an exception from a void method, I have to use doThrow.  </p>
  
  <p>But my problem is that the compiler complains that the call to Mockito.doThrow() is throwing RuntimeException...so then I have to add a throws clause to the method setting up the mock.  Is that a bug in Mockito itself?  doThrow is declaring something that should happen in the future, but not during the setup of the mock.</p>
  
  <p>My OuterClass looks like...</p>
  
  <pre><code>public class OuterClass {
    protected InnerClass inner;
    protected void createInner() { inner = new InnerClass(); }
    protected doSomething() {
      try {
        inner.go();
      } catch (RuntimeException re) {
        throw new MyException("computer has caught fire");
      }
    }
  }
  </code></pre>
  
  <p>And my test code looks like...</p>
  
  <pre><code>@Test(expected = MyException.class)
  public void testSomething() {
    OuterClass outer = new TestOuterClass();
    outer.doSomething();
  }
  
  public static class TestOuterClass extends OuterClass {
    @Override
    public void createInner() {
      InnerClass mock = Mockito.mock(InnerClass.mock);
      Mockito.doThrow(new RuntimeException("test")).when(mock).go();  // PROBLEM
      inner = mock;
    }
  }
  </code></pre>