You can use answers
:
val otm: ObjectToMock = mockk()
every { otm.methodToCall(any(), any())} answers {
secondArg<(String) -> Unit>().invoke("anything")
}
otm.methodToCall("bla"){
println("invoked with $it") //invoked with anything
}
Within the answers
scope you can access firstArg
, secondArg
etc and get it in the expected type by providing it as a generic argument. Note that I explicitly used invoke
here to make it more readable, it may also be omitted.