I have to unit test some old code that wasn’t designed to support unit testing (No DI). Is there a way to mock an object that is being initialized within a public method?
public int method() {
A a = new A(ar1, arg2); //How to mock this?
}
Thanks,
-Abidi
Another option is to refactor the code into
In your test method now you can use Mockito’s
spyanddoAnswerfunctions to overridecreateAon your test fixture with something along the lines of: