mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.09k stars 198 forks source link

Mockito cannot mock function with UShort arguments #492

Open pasta18 opened 9 months ago

pasta18 commented 9 months ago

I want to mock this function:

class MyClass() {
  fun myFunction(argument: UShort): ByteArray {
    ....
  }
}
var mocked: MyClass = mock(MyClass::class.java)
doReturn(byteArrayOf()).`when`(mocked).myFunction(any())

When run test, this error occurred.

Cannot invoke "kotlin.UShort.unbox-impl()"
java.lang.NullPointerException: Cannot invoke "kotlin.UShort.unbox-impl()"
renannprado commented 8 months ago

@pasta18 did you find a workaround?

pasta18 commented 8 months ago

@renannprado No, no workaround has been found yet.

I didn't mock it, because there was no way to mock the target method.

renannprado commented 8 months ago

@pasta18 this may help in your case: https://github.com/mockito/mockito-kotlin/issues/445#issuecomment-1177218590

In my case unfortunately it didn't.