Dariusz Kuc
06/12/2019, 11:00 PMclass MockkCaptorTest {
@Test
fun `verify mockk captor behavior`() {
val simpleMockk = mockk<Simple> {
every { hello(any(), any()) } answers { "Mocked response for ${arg<String>(0)}, age: ${arg<Int>(1)}" }
}
simpleMockk.hello("Bob", 2)
simpleMockk.hello("Alice", 1)
val bobsAge = slot<Int>()
verify {
simpleMockk.hello("Bob", capture(bobsAge))
}
assertEquals(2, bobsAge.captured)
}
}
class Simple {
fun hello(name: String, age: Int) = "Hello $name, age: $age"
}
above will actually capture Alice
ageLeoColman
06/12/2019, 11:48 PMDariusz Kuc
06/12/2019, 11:50 PMLeoColman
06/12/2019, 11:53 PMevery
blockDariusz Kuc
06/13/2019, 12:47 AM