Mockito can mock static methods using the mockito-inline extension (bundled by default since Mockito 5) via the try-with-resources MockedStatic API.
To test code calling LocalDate.now(), you can mock the static method so the test always sees a fixed date instead of the real current date.
try (MockedStatic<LocalDate> mocked = mockStatic(LocalDate.class)) {
mocked.when(LocalDate::now).thenReturn(LocalDate.of(2024, 1, 1));
assertEquals(LocalDate.of(2024, 1, 1), reportService.today());
}A concise interview answer is
Since Mockito 3.4 you can mock static methods with mockStatic() inside a try-with-resources block, stubbing calls with mocked.when(ClassName::method).thenReturn(value). It requires the inline mock maker, and I use it sparingly since heavy static usage is usually better refactored to be injectable.
Last updated: 16 July 2026
Previous question: How does ArgumentCaptor work in Mockito? Can you give an example?
Next question: What is the difference between verify() and verifyNoMoreInteractions() in Mockito?