我正在尝试找出以下内容:
我有一个模拟的方法,在这个模拟的类中有一个函数,该函数的参数不带任何值且无效返回,类似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。