title: Mockito - deep stubbing
body: <p>I am using Mockito to test my classes. I am trying to use Deep stubbing as I didn't a way on injecting a Mock inside another mock object in Mockito.</p>
  
  <pre><code>class MyService{
  
      @Resource
      SomeHelper somehelper;
  
      public void create()
      {
          //....
          somehelper.invokeMeth(t);
      }
  }
  
  class SomeHelper{
      @Resource
      private WebServiceTemplate webServiceTemplate;
  
      public void invokeMeth(T t)
      {
          try{
              //...
              webServiceTemplate.marshalSendAndReceive(t);
          }catch (final WebServiceIOException e) {
              throw new MyAppException("Service not running");
          }
      }
  }
  </code></pre>
  
  <p>Now I am trying to Unit test the MyService class's create() method.
  I have injected a mock for SomeHelper as follows</p>
  
  <pre><code>@Mock(answer = Answers.RETURNS_DEEP_STUBS)
  SomeHelper somehelper;
  </code></pre>
  
  <p>What I want now is when  the invokeMeth() method gets called on the mocked somehelper object it calls the real method in this case.</p>
  
  <pre><code>when(somehelper.invokeMeth(isA(RequestObject.class)))
      .thenCallRealMethod();
  </code></pre>
  
  <p>I was expecting the webServiceTemplate not be null in this case.</p>
  
  <p>However I get a Nullpointer exception when the code tries to execute the line</p>
  
  <pre><code>webServiceTemplate.marshalSendAndReceive(t);
  </code></pre>
  
  <p>Any clue how I can get access to a deep mock object (i.e. mock within a mock - in this case webserviceTemplete mock inside somehelper mock) and then apply a when condition to throw a  WebserviceIOException ?
  I want this so that I can test the MyService.create() to check it behaves properly when a WebServiceIOException is thrown down the code.</p>