PowerMockito is calling the method when I use doReturn(..).when(....)
<p>I'm new to PowerMockito and there's a behavior it's displaying which I don't understand. The following code explains my issue:</p>

<pre><code>public class ClassOfInterest {

  private Object methodIWantToMock(String x) {

    String y = x.trim();

    //Do some other stuff;
  }

  public void methodUsingThePrivateMethod() {

    Object a = new Object();
    Object b = methodIWantToMock("some string");

    //Do some other stuff ...
  }
}
</code></pre>

<p>I have a class which contains a private method that I want to mock called <code>methodIWantToMock(String x)</code>. In my test code, I'm doing the following:</p>

<pre><code>@RunWith(PowerMockRunner.class)
@PrepareForTest(ClassOfInterest.class)
public class ClassOfInterestTest {

  @Test
  public void someTestMethod() {

  ClassOfInterest coiSpy = PowerMockito.spy(new ClassOfInterest());

  PowerMockito.doReturn(null).when(coiSpy, "methodIWantToMock", any(String.class));

  coiSpy.methodUsingThePrivateMethod();

  //Do some stuff ...

  }
}
</code></pre>

<p>According to the above code, PowerMockito should simply return a null whenever <code>methodIWantToMock</code> is called inside <code>methodUsingThePrivateMethod()</code> when I run the test above. However what actually happens is that when this command is run: <code>PowerMockito.doReturn(...).when(...)</code>, <strong>PowerMockito is actually calling <code>methodIWantToMock</code> right then and there !!</strong> Why is it doing that ?? At this stage I only wanted to specify how it should mock the private method once it's <strong><em>eventually</em></strong> called when the <code>coiSpy.methodUsingThePrivateMethod();</code> line is run.</p>