I want to verify that a public static void
method has been called.
@RunWith(PowerMockRunner.class)
@PrepareForTest({ConsoleLog.class})
public class AdContentDataUnitTest {
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(ConsoleLog.class);
}
@Test
public void adContentData_sendTrackingEvent_noUrl() throws Exception {
mAdContentData = spy(mAdContentData);
// PowerMockito.doNothing().when(ConsoleLog.class);
verifyStatic();
mAdContentData.sendTrackingEvent("event1");
//verifyStatic();
}
}
sendTrackingEvent
will be invoked, and the ConsoleLog.v(String, String)
will be called. I can see in debug that the static method is called, but the following log appear and the test fail:
Wanted but not invoked com.example.logger.ConsoleLog.v(
"AdContentData",
"sendTrackingEvent: event event1 does not exist."
);
I've tried to add the verifyStatic
after but same log, and if I remove the first verify, nothing is checked. If I mock the whole ConsoleLog class the error Unfinished stubbing detected here: [...] PowerMockitoCore.doAnswer
appear.
Does anyone know how to do it properly?