Mockito.mockStatic()
Mock static methods without PowerMock
try (MockedStatic<Foo> dummyStatic = Mockito.mockStatic(ClassName.class)) {
dummyStatic.when(() -> ClassName.method("param1"))
.thenReturn("someValue");
// when
System.out.println(ClassName.method("param1"));
//then
dummyStatic.verify(
() -> ClassName.method("param1"),
times(1),
);
}Last updated