Open utterances-bot opened 1 month ago
Thank you for sharing.
import org.mockito.Mockito
import org.mockito.Mockito.mock
import org.mockito.Mockito.`when`
import org.mockito.kotlin.any
@MockBean(UserRepository::class)
fun userRepository(): UserRepository {
return mock(UserRepository::class.java)
}
@Test
fun createUser() {
`when`(userRepository.createTest(any<User>())).thenAnswer{
val user = it.arguments[0] as User
user.id = 300L
user
}
And errors are all the same
You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
when(mock.get(anyInt())).thenReturn(null);
doThrow(new RuntimeException()).when(mock).someVoidMethod(any());
verify(mock).someMethod(contains("foo"))
What`s wrong? Thanks
Mockito and non-null types in Kotlin | Damir's Corner
https://www.damirscorner.com/blog/posts/20221223-MockitoAndNonNullTypesInKotlin.html