Kulwinder Singh
03/10/2020, 1:30 PMMockKException: no answer found for: MyClass(#1).sendMessage(okhttp3.RequestBody$2@4ed4bd33)
,
actually RequestBody's properties are same just instance is different. that's why it did not matches parameters but if i add any()
instead of requestbody it works. is there anything else i can use instead of any()
here ?
every { myClass.sendMessage(MockRequest.createTestBody(value="text")) } answers { something }
....
class SomeObject(myClass:MyClass){
fun doSomething(text: String): Flowable<Result<Boolean>> {
val request = MockRequest.createTestBody(text)
myClass.sendMessage(request)
}
}
....
i have checked documentation of mockk but didn't found anything, that's why asked here:Cody Engel
03/10/2020, 3:31 PMany
and if it's important to verify the contents I'll use a verify
call on the mock to verify that the correct value was being passed (assuming that's important for the test).Kulwinder Singh
03/10/2020, 3:38 PMCody Engel
03/10/2020, 3:42 PMverify { myClass.sendMessage(request) }
Kulwinder Singh
03/11/2020, 1:56 AMverify
is saying that instances of RequestBody don't matchCody Engel
03/11/2020, 2:08 AMKulwinder Singh
03/11/2020, 2:41 AMCody Engel
03/11/2020, 2:41 AMKulwinder Singh
03/11/2020, 2:43 AMlateinit property captured has not been initialized
kotlin.UninitializedPropertyAccessException: lateinit property captured has not been initialized
at io.mockk.CapturingSlot.getCaptured(API.kt:2529)
val firstSlot= slot<RequestBody>()
every { myClass.sendMessage(firstSlot) } answers { something }
it("sendSomeMessage") {
...
verify {
myClass.sendMessage(firstSlot.captured)
}
}
Cody Engel
03/11/2020, 2:48 AMKulwinder Singh
03/11/2020, 2:54 AMevery { myClass.sendMessage(capture(firstSlot)) } answers { something }
(its changed while i edited before asking)Cody Engel
03/11/2020, 3:01 AMKulwinder Singh
03/11/2020, 3:05 AMevery
block which was similar to first but that was not using capture
. so i commented that and now i works.Cody Engel
03/11/2020, 1:28 PMKulwinder Singh
03/11/2020, 1:46 PMCody Engel
03/11/2020, 4:15 PMnull
states if the type isn't nullable.Kulwinder Singh
03/12/2020, 5:17 AM