Using PowerMockito to setup a test containing a private method ala this.
Class:
public class SomeMod {
public void somefunc() {
Logger.debug("somefunc");
...
privFunction(param);
...
}
private void privFunction(param) {
Logger.debug("privFunction");
}
}
Test:
@RunWith(PowerMockRunner.class)
@PrepareForTest({SomeMod.class})
public class somemod_test {
...
@Test public void test0() {
SomeMod_spy somemod = spy(new SomeMod());
PowerMockito.when(somemod, "privFunction", "param").thenReturn(someMockedValue);
...
somemod.somefunc();
}
}
When I run this and set breakpoints on both Logger.debug statements Im seeing the privFunction
get hit before the somefunc
. If I comment out the call to somemod.somefunc()
in the test, the privFunction
is still getting hit.
What am I doing wrong?
Edit:
I used PowerMockito.when().thenReturn()
instead of the recommeded PowerMockito.doReturn().when()
syntax as the former throws NPE and UnfinishedStubbingException. This suggests that my test environment isn't setup properly. Not sure where to look to fix this.