I\'m trying to spy on an Object and I want to stub a method that is called by the constructor before the constructor calls it.
My class looks like that:
Use PowerMock.
After you've imported the libraries, set it up to manipulate the class you want to mock with the instance method that mustn't be called.
Like so:
@RunWith(PowerMockRunner.class)
@PrepareForTest({, Myclass.class})
Like so:
suppress(method(Myclass.class, "setup"));
Like so:
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
// code here
return null;
}
}).when(Myclass.class, "setup");