I am testing a method in class which in turn calls another artifacts' method and consume return value in it.
public void methodToTest()
{
Object reply = artifactObj.anotherMethod(object);
if(reply == null)
return;
Object =reply.getData();
}
I have used powermockito and know that if "anotherMethod" existed inside the same class I could have easily spied it over. But I am not sure how can I do same when method is not in same class.
My attempt-:
Object mockObject = mock(Object.class);
Object mockReply = mock(Object.class);
Mockito.when(artifactObj.anotherMethod(mockObject)).thenReturn(mockReply);
//Now call original test method
Class c = new Class(artifactObj);
c.methodToTest();
doing above will always return reply = null inside original method that I am trying to test. I need some value of reply to be returned so that I can use it inside my method.