I know I read the answer somewhere, but how can I ...
# mockk
t
I know I read the answer somewhere, but how can I mock a method like
fun updateParticipant(participant: Participant, update: Participant.() -> Unit)
? I am trying with
Copy code
val participantOrchestrationService: ParticipantOrchestrationService = mockk(relaxed = true)
val dummy = Participant()
val update = slot<Participant.() -> Unit>()
every { participantOrchestrationService.updateParticipant(dummy) { capture(update) } } just Runs
update.captured(dummy)
dummy should {
	it.state == State.inactive
}
but getting
kotlin.UninitializedPropertyAccessException: lateinit property captured has not been initialized
any suggestion?
I went on with
every { participantOrchestrationService.updateParticipant(dummy, captureLambda()) } answers { lambda<Participant.() -> Unit>().invoke(dummy) }
instead of the original
every
block (and remove
update
o
Can you please put the code to gist? It is very hard to read
t
thanks for the feedback. While creating a gist with a smaller example, I actually found the problem and it was in my code. the signature of
updateParticipant
is
fun updateParticipant(participant: Participant, update: Participant.() -> Unit = {}) : Unit
the
every
block should be
every { participantOrchestrationService.updateParticipant(dummy, capture(update)) } just Runs
, having
capture
in a lambda itself satisfied the compiler, but ofc the capturing itself never run. It was kinda of a dummy mistake. sorry for wasting your time
o
Nws