doAnswer

infix fun <T> OngoingStubbing<T>.doAnswer(answer: Answer<*>): OngoingStubbing<T>

Sets a generic answer to be applied when the stubbed method/function is being called. E.g:

    val answer = Answer { "result" }
whenever { mock.someFunction() } doAnswer answer

This function is an alias for Mockito's OngoingStubbing.thenAnswer.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

answer

to be applied on the method/function invocation.


infix fun <T> OngoingStubbing<T>.doAnswer(answer: (KInvocationOnMock) -> T?): OngoingStubbing<T>

Sets an answer to be applied when the stubbed method/function is being called, specified by a lambda. E.g:

    whenever { mock.someFunction() } doAnswer { "result" }

This function is an alias for Mockito's OngoingStubbing.thenAnswer.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

answer

to be applied on the method/function invocation.


fun <T> doAnswer(answer: (KInvocationOnMock) -> T): Stubber

Sets a generic answer, specified with a lambda, to be applied in reverse stubbing.

Example:

    doAnswer { "result" }.whenever(mock).someMethod()

This function is an alias for Mockito's Mockito.doAnswer.

See examples in javadoc for Mockito class

Return

Stubber object used to stub fluently.

Parameters

answer

to answer to apply when the stubbed method/function is being called.