title: Mockito.doReturn().when() is not working - the unit test keeps on calling the original method
body: <p>I am writing an unit test for a SOAP API in which I need to mock the response of a certain method, which is however called all the time. </p>
  
  <p>The (relevant) code of my unit test is the following: </p>
  
  <pre><code>import org.mockito.Matchers;
  import org.mockito.Mock;
  import org.mockito.Mockito;
  import org.mockito.MockitoAnnotations;
  
  
  public class PricingSessionTest{
  
      @Test
      public void testPricingOfStrategyWithCorrectFormat() throws Exception {
  
          //[...other code...]
          PricingSessionImpl pricingSession = new PricingSessionImpl(this.session);
          PricingSessionImpl spyPricingSession = Mockito.spy(pricingSession);
          Mockito.doReturn(myResult)
                 .when(spyPricingSession)
                 .send(
                     Mockito.any(MxML.class),
                     Matchers.eq(ACTION_PRICE),
                     Matchers.eq(TimeoutDuration),
                     Matchers.eq(TimeoutUnit)
                  );
          List&lt;PricingResult&lt;?&gt;&gt; pricedProducts = pricingSession.price(listOfProductsToPrice);        
      }
  </code></pre>
  
  <p>Inside the method <code>.price()</code> of the spied object <code>pricingSession</code> (type <code>PricingSessionImpl</code>) there is a call to the following method: </p>
  
  <pre><code>protected List&lt;MxDocument&gt; send(MxML mxml, String action, long timeout, TimeUnit timeoutUnit) throws RequestException, RequestTimeoutException 
  </code></pre>
  
  <p>The implementation of the method is found in the parent class <code>public abstract class AbstractPricingSession</code> (but the method itself is not <code>abstract</code>), you can find the hierarchy below: </p>
  
  <p><a href="https://i.stack.imgur.com/4EANz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4EANz.png" alt="enter image description here"></a></p>
  
  <p>When I debug this unit test, at some point I get in front of a call to the method I want to mock: </p>
  
  <pre><code>List&lt;MxDocument&gt; documents = send(mxml, ACTION_PRICE, getTimeoutDuration(), getTimeoutUnit());
  </code></pre>
  
  <p>In here, I would expect my <code>Mockito</code> to return me <code>myResult</code>, since the call to the method <code>send()</code> in the class <code>PricingSessionImpl</code> is done with a parameter of type <code>MxML</code> and then one <code>String</code>, one <code>long</code> and one <code>TimeUnit</code> which are exactly what I'm passing to the <code>.when()</code>. </p>
  
  <p>However, the method keeps on getting called. </p>
  
  <p>Can anyone point me towards the good direction to debug this issue? Please note I've checked the multiple questions/answers on this subject already present in the web, but didn't find anything helpful for my specific case so far.<br>
  In case you need to see more in the code, don't hesitate to ask. </p>