java - PowerMock - Suppress constructor but set private final field -
when suppressing constructor of class using powermock, how can set value of private final field?
suppressing constructor:
suppress(constructor(abc.class, mytype.class)); abc abc = spy(new abc(null)); // using correct value doesn't work abc.somemethod();
the class tested:
class abc { private final mytype test; public abc(mytype test) { this.test = test; // executes code suppressed } public void somemethod() { test.dosomethingelse(); } }
as would, using reflection:
field f = abc.class.getdeclaredfield("test"); f.setaccessible(true); f.set(abc, new mytype());
this not related mocking , therefore nothing mocking framework target in api. should consider refactor testing.
Comments
Post a Comment