Another option is to reorganize the code into
public int method() { A a = createA(arg1,arg2); } A createA(int arg1, int arg2) { return new A(arg1,arg2); }
In your test method, you can now use the Mockito spy and doAnswer to override createA on your test device with something like strings:
Foo foo = new Foo(); Foo spiedFoo = spy(foo);
source share