是否可以对带有参数类型为无参数且无结果的参数的函数进行断言?

时间:2020-10-08 12:53:27

标签: kotlin mockito

我正在尝试找出以下内容:

我有一个模拟的方法,在这个模拟的类中有一个函数,该函数的参数不带任何值且无效返回,类似What does ".()" mean in Kotlin?

fun invokeStuff(values: (MyParametersBuilder.() -> Unit)) {
        // do something and extract values
    }

MyParametersBuilder类具有一些用于其自身属性的设置方法。

所以当我调用它时,我会这样做

MyClass().invokeStuff{
     setEnableFlagA(true)
}

所以现在使用Mockito遇到了一个问题,因为我不知道如何执行甚至不可能,所以无法模拟invokeStuff的结果。

基本上,我不能这样做:

when(myClass.invokeStuff(any(MyParametersBuilder)).thenReturn... <- it says this method doesn't exist

都不是

when(myClass.invokeStuff{any(Boolean::class.java)}.thenReturn... <- compiles but doesnt match anything

when(myClass.invokeStuff{}.thenReturn... <- doesn't match either

任何想法我该怎么做?我正在使用Kotlin和Mockito。

0 个答案:

没有答案
相关问题