mockito-kotlin icon indicating copy to clipboard operation
mockito-kotlin copied to clipboard

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

Open pikaboo opened this issue 5 years ago • 1 comments
trafficstars

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 ?

pikaboo avatar Feb 22 '20 06:02 pikaboo

@pikaboo Could you post the test that fails?

bohsen avatar Feb 22 '20 19:02 bohsen