title: Mockito and nested method call
body: <p>I have 3 classes:</p>
  
  <pre><code>public class SomeDAO {
  
     // that method I'd want to catch and change
     public void getObj() { ... }
  
  }
  
  public class MainService {
  
      private Service2 service2;
  
      public void doMain() {
          service2.doSomethingAnother();
      }
  
  }
  
  public class Service2 {
  
      private SomeDAO someDAO
  
      public void doSomethingAnother() {
          someDAO.getObj();
      }
  }
  </code></pre>
  
  <p>All I need - to call <em>doMain</em> but with custom <em>someDao.getObj()</em> inside <em>service2.doSomethingAnother()</em>:</p>
  
  <pre><code>public TestClass {
  
      @InjectMocks
      private final MainService mainService = new MainService();
  
      @InjectMocks
      private final Service2 service2 = new Service2();
  
      @Mock
      private SomeDAO someDao;
  
      @Test
      public void testMe() {
  
          // substitution
          when(someDao.getObj()).thenReturn(new MyObj());
  
          // then I'm calling the outer method
          mainService.doMain();
  
      }
  
  }
  </code></pre>
  
  <p>When running that test I have NPE in <strong>mainService.doMain()</strong>: service2 in null..</p>
  
  <p>Inside of <strong>testMe</strong> object <em>service2</em> is alive and not null, it has been declared as class variable and initialized. </p>
  
  <p>Whether I misundersood @InjectMock behaviour?</p>