mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.1k stars 200 forks source link

Cant stub a method with (Boolean)->Unit parameter #375

Open pikaboo opened 4 years ago

pikaboo commented 4 years ago

I have

open class Mockable {
  open fun testWithEmptyCallback(someString: String, anotherString: String, callback:() -> Unit)
  open fun testWithBooleanCallback(someString: String, anotherString: String, callback:(Boolean) -> Unit)
}

Then I do

val mock = mock<Mocable> {
    on { testWithEmptyCallback(any(),any(),any()}. then { (it.argmuents.last() as? ()->Unit).invoke()}
    on { testWithBooleanCallback(any(),any(),any()}. then { (it.argmuents.last() as? (Boolean)->Unit).invoke(true)}
}

The first invocation with testWithEmptyCallback works just fine but if the second line is written with testWithBooleanCallback I get the following exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference

How to fix it ?

bohsen commented 4 years ago

@pikaboo Could you post the test that fails?