I am new to PowerMockito, and there the behavior that I show I do not understand. The following code explains my problem:
public class ClassOfInterest {
private Object methodIWantToMock(String x) {
String y = x.trim();
}
public void methodUsingThePrivateMethod() {
Object a = new Object();
Object b = methodIWantToMock("some string");
}
}
I have a class that contains a private method that I want to mock under the name methodIWantToMock(String x). In my test code, I do the following:
@RunWith(PowerMockRunner.class)
@PrepareForTest(ClassOfInterest.class)
public class ClassOfInterestTest {
@Test
public void someTestMethod() {
ClassOfInterest coiSpy = PowerMockito.spy(new ClassOfInterest());
PowerMockito.doReturn(null).when(coiSpy, "methodIWantToMock", any(String.class));
coiSpy.methodUsingThePrivateMethod();
}
}
PowerMockito , methodIWantToMock methodUsingThePrivateMethod(), . , : PowerMockito.doReturn(...).when(...), PowerMockito methodIWantToMock !! ? , , coiSpy.methodUsingThePrivateMethod();.