maxmello
12/03/2018, 4:01 PMrepository.save(entity)
method to just return whatever is passed into it. I thought that Slot
would be the correct way of doing this, but …
val slot = slot<Entity>()
every { repository.save(capture(slot)) } answers { slot.captured }
… does not work, because the slot.captured is lateinit and not initialized during initialization of the mocks. Am I missing something or is this not possible with mockK?robin
12/03/2018, 7:18 PMevery { repo.save(any()) } answers { invocation.args[n] as XYZ }
where XYZ is the type of the argument passed in.inline infix fun <reified T> MockKStubScope<T, T>.returnsArgument(n: Int): MockKAdditionalAnswerScope<T, T> =
this answers { invocation.args[n] as T }
every { repo.save(any()) } returnsArgument 0
oleksiyp
12/03/2018, 10:02 PMmaxmello
12/04/2018, 7:45 AM