I am trying to verify that a static method is not called in a certain configuration, in a unit test.
I am thus using PowerMock (powermock-core:2.0.4
& powermock-module-junit4:2.0.4
) and its Mockito API (powermock-api-mockito2:2.0.4
).
When doing
PowerMockito.mockStatic(MyClass.class);
serviceUnderTest.methodThatShouldNotCallStaticMethod(arg1, arg2); //service not of type MyClass of course
PowerMockito.verifyStatic(MyClass.class, never());
MyClass.staticMethod(any(), any());
on a test method within a class annotated with
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClass.class})
I get the following error : org.mockito.exceptions.misusing.NotAMockException:
Argument passed to verify() is of type Class and is not a mock!
.
What did I do wrong and how to solve it ?
Thanks
It turned out to be a Powermock bug...
Here is the workaround for anyone who could be interested :
testImplementation 'org.mockito:mockito-inline:2.13.0
" in gradle src\test\resources\org\powermock\extensions\configuration.properties
file composed of the single line mockito.mock-maker-class=mock-maker-inline
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With