I have a method in my MainActivity
and I want to mock the A
instance :
public void some_method() {
A a = new A();
....
}
so I tried creating in the MainActivity
class a method
public A createA(){return new A()}
and then some_method
becomes
public void some_method() {
A a = createA();
....
}
I tried this
MainActivity mainActivitySpy = (MainActivity)Mockito.spy(MainActivity.class);
when(mainActivity.createA()).thenReturn(null)
but I get this error message
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
Is there a way to mock the constructor ? I tried the a solution SO
post (18 points at the time of the writing, solution without Poweermockito
) but I was not able to make this work, because I don't think it is functional