how to mock an instance method invocation from static method while writing junit for static method?I'm writing tests for existing code.
class A
{
public static D methodX()
{
B b = new B();
C c = b.doSomething();
}
}
class B
{
public C doSomething()
{
return C;
}
}
class Atest
{
@Test
public void testMethodX()
{
B b =Mockito.mock(B.class);
Mockito.when(b.doSomething()).thenReturn(new C());
A.methodX();
// some assertions
}
}