title: Mockito mocking a method calls the actual method
body: <p>I am trying to mock method <code>createInstanceB()</code> using <code>Mockito.when()</code> as well as <code>doReturn()</code>. This always calls real method.</p>
  <p>For example:</p>
  <pre><code>Class A {
    public B createInstanceB(any, any) {
      B b = new B();
      b.api();
    }
  }
  </code></pre>
  <p>I am using the code below</p>
  <pre><code>import org.mockito.Mockito;
  import static org.mockito.Mockito.*;
  
      Class ATest {
        A a;
        B b;
  
        @Before
        Public void setup{
          a = A.getInstance();
          b = mock(B.class);
        }
    
        @Test
        public void testCreateInstanceB(){
          Mockito.when(a.createInstanceB(any(),any()).thenReturn(b);
          ...
        }
      }
  </code></pre>
  <p>I tried <code>doReturn(mock)</code> as well.</p>