I am trying to verify in a test that a static method is called. I am using Mockito for this purpose.
This question is similar to this. However, the solution suggested in the most upvoted reply is not applicable anymore as the MockedStatic verify method is deprecated.
try (MockedStatic<SomePublicClass> dummyStatic = Mockito.mockStatic(SomePublicClass.class)) {
dummyStatic.when(() -> SomePublicClass.myPublicStaticFunc(anyInt()))
.thenReturn(5);
// when
System.out.println(SomePublicClass.myPublicStaticFunc(7));
//then
dummyStatic.verify(
times(1),
() -> SomePublicClass.myPublicStaticFunc(anyInt())
);
}
The alternative is to call
verify(dummyStatic).myPublicStaticFunc(anyInt);
However, it complains that the method myPublicStaticFunc(int) is undefined for the type MockedStatic.
What are my alternatives, or what am I missing. Also, I know I can try this using PowerMock, but for the moment, I am trying to get this working using Mockito only.
mockito
do you use. In 3.5.13 it is not deprecated. – Kusin