I am trying to test some code using the PowerMockito spy, and I complete the method (getRootTagMap - see below) to return the value constructed in the test (using PowerMockito because the method is private.)
However, instead of returning a value, it always calls the actual method, rather than returning the constructed value.
Not sure what I'm doing wrong
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.powermock.api.mockito.PowerMockito.spy;
@RunWith(PowerMockRunner.class)
@PrepareForTest({JsonAppMessageProcessor.class})
public class TestPropStoreAppController {
@Test public void testSaveJsonAppTagChangesToPropStore() throws Exception {
JsonAppMessageProcessor messageProcessorSpy = spy(new JsonAppMessageProcessor());
when(messageProcessorSpy, "getRootTagMap", any(JsonAppTag.class)).thenReturn(constructReturnValue());
messageProcessorSpy.saveChanges(constructParameterForChanges());
}
}
source
share