So my code looks something like this
class One
{
   private final Two two;
   public One()
   {
       two = new Two(this)
   }
   public void method1()
   {
       //do something
       method2();
   }
   public void method2()
   {
       //do something
       two.method3();
    }
}
class Two
{
    private final One one;
    public Two(One one)
    {
        this.one=one;
     }
    public void method3()
    {
        //print something
    }
}
Now, i'd like to mock method3() in class Two while i test method1() of class One and my Junit is like this.
private One one;
private Two two;
@Before
public void setup()
{
    one = Mockito.spy(new One());
    two = Mockito.spy(new Two(one));
}
    
@Test
pubic void testMethod1InClassOne()
{
    Mockito.doNothing().when(testTwo).method3();
    testOne.method1();
}
But somehow, method3() is not getting mocked and i'm still seeing the contents its printing. However, i can successfully mock method2(). maybe because method2() is directly called from method1() which is the method i am testing? Please suggest how can i mock method3.
Thanks, Meher
 
    