At class level I have:
@ExtendWith(SpringExtension::class)
@AutoConfigureMockMvc
@SpringBootTest
@PrepareForTest(LocalDateTime::class)
My test method contains this:
@Test
fun `testMethod`() {
PowerMockito.mockStatic(LocalDateTime::class.java)
Mockito.`when`(LocalDateTime.now()).thenReturn(LocalDateTime.of(2018, 8, 22, 10, 0, 0, 0));
}
My build.gradle.kts
testImplementation ( "org.mockito:mockito-core:3.5.9")
testImplementation("org.powermock:powermock-api-mockito2:2.0.7")
testImplementation("org.powermock:powermock-module-junit5:1.6.4")
The error:
org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles);
How to mock LocalDateTime.now()
with Kotlin, Junit5, Spring Boot 2, Mockito, and PowerMock?
(I don't want to use LocalDateTime.now(clock) method)