title: How can I mock protected method of parent class?
body: <p>I try to mock protected method of the parent class. For that reason I use <code>Mockito</code> &amp; <code>PowerMockito</code>. My parent class.</p>
  
  <pre><code>public class Parent {
      protected int foo() {
          throw new RuntimeException("Do not invoke this method.");
      }
  }
  </code></pre>
  
  <p>My child class.</p>
  
  <pre><code>public class Child extends Parent {
      protected int boo() {
          return super.foo();
      }
  }
  </code></pre>
  
  <p>And test class.</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest({Parent.class, Child.class})
  public class ChildTest {
  
      @Mock
      private Child childMock;
  
      @Before
      public void before() {
          initMocks(childMock);
      }
  
      @Test
      public void shouldInvokeProtectedMockedMethod() throws Exception {
          /* Given */
          PowerMockito.doReturn(500).when(childMock, "foo");
          /* When */
          childMock.boo();
          /* Then */
          Mockito.verify(childMock, Mockito.times(1)).boo();
          Mockito.verify(childMock, Mockito.times(1)).foo();
      }
  
      @After
      public void after() {
          Mockito.reset(childMock);
      }
  }
  </code></pre>
  
  <p>When I run it I get this error</p>
  
  <pre><code>Wanted but not invoked:
  child.foo();
  -&gt; at com.test.ChildTest.shouldInvokeProtectedMockedMethod(ChildTest.java:36)
  
  However, there were other interactions with this mock:
  child.boo();
  -&gt; at com.test.ChildTest.shouldInvokeProtectedMockedMethod(ChildTest.java:33)
  </code></pre>
  
  <p>What I'm doing wrong?</p>