thanksforallthefish
10/23/2020, 9:45 AM@Test // <- junit5 annotation
fun publisher() {
val publisher = mockk<Publisher>(relaxed = true)
UseCase(publisher).doSomething()
verify { publisher.publish(any<UseCase.Something>()) }
verify { publisher.publish(any<String>()) }
}
interface Publisher {
fun publish(any: Any)
fun publish(event: Event) {
publish(event as Any)
}
class Event(source: Any)
}
class UseCase(val publisher: Publisher) {
fun doSomething() {
publisher.publish(Something(""))
}
data class Something(val something: String)
}
the test passes. what am I not seeing?jlw
10/27/2020, 3:28 PMany
doesn’t pass the type info to the matcher. The type info is just there to satisfy the method parameter requirements:
inline fun <reified T : Any> any(): T = match(ConstantMatcher(true))
Because both UseCase.Something
and String
are subs of Any
, this test passes because it is called at least once.