I got this exception when mock the LocalDate.now() static method with Mockito.mockStatic().
org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: at utils.PowerMockTest.test(PowerMockTest.java:18)
E.g. thenReturn() may be missing.
Examples of correct stubbing: when(mock.isOk()).thenReturn(true); when(mock.isOk()).thenThrow(exception); doThrow(exception).when(mock).someVoidMethod(); Hints:
- missing thenReturn()
- you are trying to stub a final method, which is not supported
- you are stubbing the behaviour of another mock inside before 'thenReturn' instruction is completed
code is
public class MockStaticTest {
@Test
void test(){
LocalDate today=LocalDate.of(2020,11,20);
try (MockedStatic mocked = mockStatic(LocalDate.class)) {
mocked.when(LocalDate::now).thenReturn(LocalDate.of(2020,11,10));
Assertions.assertEquals(today,LocalDate.now());
mocked.verify(atLeastOnce(),LocalDate::now);
}
}
}
I'm a bit confused by the exception message because I certainly added thenReturn statement.
Any help would be appreciated.