title: How do I override default Answers on a Mockito mock?
body: <p>I have the following code:</p>
  
  <pre><code>private MyService myService;
  
  @Before
  public void setDependencies() {
      myService = Mockito.mock(MyService.class, new StandardServiceAnswer());
      Mockito.when(myService.mobileMethod(Mockito.any(MobileCommand.class), Mockito.any(Context.class)))
              .thenAnswer(new MobileServiceAnswer());
  }
  </code></pre>
  
  <p>My intention is that all calls to the mocked <code>myService</code> should answer in a standard manner. However calls to <code>mobileMethod</code> (which is public) should be answered in a specific way.</p>
  
  <p>What I'm finding is that, when I get to the line to add an answer to calls to <code>mobileMethod</code>, rather than attaching the <code>MobileServiceAnswer</code>, Java is actually invoking <code>myService.mobileMethod</code>, which results in an NPE.</p>
  
  <p>Is this possible? It would seem like it should be possible to override a default answer.
  If it is possible, what is the correct way to do it?</p>
  
  <h2>Update</h2>
  
  <p>Here are my <code>Answer</code>s:</p>
  
  <pre><code>private class StandardServiceAnswer implements Answer&lt;Result&gt; {
      public Result answer(InvocationOnMock invocation) {
          Object[] args = invocation.getArguments();
  
          Command command = (Command) args[0];
          command.setState(State.TRY);
  
          Result result = new Result();
          result.setState(State.TRY);
          return result;
      }
  }
  
  private class MobileServiceAnswer implements Answer&lt;MobileResult&gt; {
      public MobileResult answer(InvocationOnMock invocation) {
          Object[] args = invocation.getArguments();
  
          MobileCommand command = (MobileCommand) args[0];
          command.setState(State.TRY);
  
          MobileResult result = new MobileResult();
          result.setState(State.TRY);
          return result;
      }
  }
  </code></pre>