I have a Tool class with two static methods, doSomething(Object) and callDoSomething(). The names are intuitive in that callDoSomething delegates its call to doSomething(Object);
public class Tool { public static void doSomething( Object o ) { } public static void callDoSomething() { doSomething( new Object()); } }
I have a Test class for Tool and I'd like to verify if doSomething(Object) was called (I want to do Argument Matching too in the future)
@RunWith( PowerMockRunner.class ) @PrepareForTest( { Tool.class } ) public class ToolTest { @Test public void toolTest() { PowerMockito.mockStatic( Tool.class ); Tool.callDoSomething();// error!! //Tool.doSomething();// this works! it gets verified! PowerMockito.verifyStatic(); Tool.doSomething( Mockito.argThat( new MyArgMatcher() ) ); } class MyArgMatcher extends ArgumentMatcher<Object> { @Override public boolean matches( Object argument ) { return true; } } }
Verify picks up doSomething(Object) if it's called directly. I've commented this code out above. Verify does NOT pick up doSomething(Object) when using callDoSomething, (this is the code shown above). This is my error log when running the code above:
Wanted but not invoked tool.doSomething(null); However, there were other interactions with this mock. at org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.performIntercept(MockitoMethodInvocationControl.java:260) at org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.invoke(MockitoMethodInvocationControl.java:192) at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:105) at org.powermock.core.MockGateway.methodCall(MockGateway.java:60) at Tool.doSomething(Tool.java) at ToolTest.toolTest(ToolTest.java:22) ... [truncated]
I'd like to avoid making any changes to the Tool class. My question is, how can I verify doSomething(Object) was called from callDoSomething(), as well as perform some argument matching on doSomething's param