Refering to mock methods in same class
class Temp() {
public boolean methodA(String param) {
     try {
         if(methodB(param))
               return true;
         return false;
     } catch (Exception e) {
           e.printStackTrace();
     }
}
}
The test class
@Test
public void testMethodA() {
Temp temp = new Temp();
Temp spyTemp = Mockito.spy(temp);
Mockito.doReturn(true).when(spyTemp).methodB(Mockito.any()); 
boolean status = temp.methodA("XYZ");
Assert.assertEquals(true, status);
}
When calling the real class temp to methodA should return the mocked method B value. Thus returning true. Why is this incorrect. I encounter the same problem. I want to run the test on the real class and not for mock object as suggested by the answer. I want to run the class methodA and expect the mocked object spyTemp methodB value when it is called