title: Mockito thenCallRealMethod method calls other mocked class as real
body: <p>I have a class with two methods and i want to test one of them but it uses the other method. Therefore, i have to use Mock annotation to mock all methods and use thenCallRealMethod to test my method. I applied this approach and it worked. But, i faced an another problem. The problem is caused by my testing method which wrapped by thenCallRealMethod. It didn't use Mocked classes and invoked real classes. So, it caused null pointer error. Thanks for any comments.</p>
  <p><strong>Test</strong></p>
  <pre><code>...
  
  @Mock
  ClassA a;
  
  @Mock
  ClassB b;
  
  @Test
  public void testing() {
  
  Mockito.when(ClassB.methodX()).thenReturn(x);
  Mockito.when(ClassA.methodZ()).thenReturn(Mockito.Any());
  Mockito.when(ClassA.methodY()).thenCallRealMethod();
  ClassA.methodY();
  
  }
  
  ...
  </code></pre>
  <p><strong>ClassA</strong></p>
  <pre><code>...
  @Autowired
  ClassB b;
  public byte[] methodZ(){
  ...
  }
  public void methodY(){
  b.methodX();
  methodZ();
  }
  ...
  </code></pre>