I am trying to use Mockito on my mocked object in such a way that it should always return the very same object that was passed in as an argument. I tried it do to it like so:
private val dal = mockk<UserDal> {
Mockito.`when`(insert(any())).thenAnswer { doAnswer { i -> i.arguments[0] } }
}
However, this line always fails with:
io.mockk.MockKException: no answer found for: UserDal(#1).insert(null)
The insert(user: User)
method doesn't take in null
as an argument (obviously User
is not a nullable type).
How can I make the insert()
method always return the same object that it received as an argument?