title: Mockito: Mock a method call inside another method
body: <p>So I'm trying to mock a method call inside another method, here's the pseudo code</p>
  
  <pre><code>class A{
  
      public String getAName(String id){
          B b = new B();
          // do something
          return b.getBName(id);
      }
  }
  
  testgetName{
  
      public void testA(){
  
          B mockB = mock(B.class);        
          Mockito.doReturn("Bar").when(mockB).getBName(id);
  
          A a = new A();
          a.getAName(id); //this still calls "b.getBName(id)" in class implementation
      }
  
  }
  </code></pre>
  
  <p>The problem here is <code>a.getAName</code> still calls  <code>b.getBName(id)</code> - not sure why?</p>
  
  <p>Any suggestions on how should I mock <code>b.getBName(id)</code> properly</p>
  
  <p>Thanks</p>