I am writing a JUnit test to verify that a static method (MyClass.myMethod()
) is never invoked in the method flow. I tried doing something like this:
PowerMockito.verifyStatic(Mockito.never());
MyClass.myMethod(Mockito.any());
In doing so I receive an UnfinisedVerificationException. How do I test that MyClass.class has no interactions whatsoever in the method execution?
UnfinishedVerificationException will occur if the Class is not mocked yet but you are trying to verify the invocation of its static method.
PowerMockito.mockStatic(MyClass.class);
underTest.testMethod();
PowerMockito.verifyStatic(Mockito.never());
MyClass.myMethod(Mockito.any());
.
.
.
This should succeed if the flow never encounters a call to MyClass.myMethod()
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