title: How can I mock methods of @InjectMocks class?
body: <p>For example I have handler:</p>
  
  <pre><code>@Component
  public class MyHandler {
  
    @AutoWired
    private MyDependency myDependency;
  
    public int someMethod() {
      ...
      return anotherMethod();
    }
  
    public int anotherMethod() {...}
  }
  </code></pre>
  
  <p>to testing it I want to write something like this:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class}
  class MyHandlerTest {
  
    @InjectMocks
    private MyHandler myHandler;
  
    @Mock
    private MyDependency myDependency;
  
    @Test
    public void testSomeMethod() {
      when(myHandler.anotherMethod()).thenReturn(1);
      assertEquals(myHandler.someMethod() == 1);
    }
  }
  </code></pre>
  
  <p>But it actually calls <code>anotherMethod()</code> whenever I try to mock it. What should I do with <code>myHandler</code> to mock its methods?</p>