Reputation: 3168
I have issue when trying to mock a method
Example (with mockito-kotlin 5.2.1, mockito-core 5.11.0, kotlin 1.9.23, kotest-assertions-core 5.6.2)
class TheBug {
@Test
fun test(): Unit = runBlocking{
val service = mock<MyService> {
onBlocking {
with(any<MyContext>()) {
myMethod()
}
}.doReturn(true)
}
with(MyContext("toto")) {
service.myMethod() shouldBe true
}
}
}
class MyService {
context(MyContext)
suspend fun myMethod(): Boolean {
return true
}
}
data class MyContext(val string: String)
Test result is
java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()"
If the method
Any idea how I could bypass it? Don't want to remove some unit tests because of it...
Upvotes: 0
Views: 77