When mocking the following interface:
interface MyDescriptor {
fun receive(): UByteArray
fun send(bytes: UByteArray)
}
with the following test code:
@Test
fun send_oneMessage(): Unit = runBlocking {
val byteStream = mockk<MyDescriptor>()
every { byteStream.send(any()) } just Runs
}
I get the following error:
io.mockk.MockKException: Failed matching mocking signature for
SignedCall(retValue=, isRetValueMock=true, retType=class kotlin.Unit, self=MyDescriptor(#1), method=send-GBYM_sE(ByteArray), args=[null], invocationStr=MyDescriptor(#1).send-GBYM_sE(null))
left matchers: [any()]
Now, if instead of any()
I use an actual UByteArray
, it runs:
@Test
fun send_oneMessage(): Unit = runBlocking {
val payload = "Payload message"
val byteStream = mockk<MyDescriptor>()
every { byteStream.send(payload.toByteArray().toUByteArray()) } just Runs
}
I can't help but to notice this part of the error: method=send-GBYM_sE(ByteArray), args=[null]
, which mentions a ByteArray
and not a UByteArray
, like if it was looking for the wrong function signature (hence the error), but I can't understand why. Changing any()
for any<UByteArray>()
results in the same error, as does using ofType(UByteArray::class)
...
However, it works with ByteArray
instead of UByteArray
:
interface MyDescriptor {
fun receive(): UByteArray
fun send(bytes: ByteArray)
}
Am I missing something?
Note: the error is similar to this question, but my test code is fairly different, hence the new question.