kotlin - 是否可以对具有无参数且无结果的函数类型参数的函数进行断言?
问题描述
我试图弄清楚以下几点:
我有一个模拟方法,在这个模拟类中有一个函数,该函数的参数不带任何内容并返回 void,类似这样的“.()”在 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。
解决方案
推荐阅读
- javascript - 使用 script 标签作为 declarativeContent.PageStateMatcher 的 CSS 条件
- r - 读取具有多个列标题的数据
- cloudflare - 使用工作人员控制 cloudflare 源服务器
- json - 快速登录应用程序后,主视图控制器没有响应
- django - 自定义注册表。确认密码
- mysql - 为什么我的 post 方法在添加 htacess 文件后只发送 1 行表数据?
- javascript - 在不修改 Amplify 库的情况下访问错误响应
- makefile - makefile 中的 '$$directoryName' 和 '$(directoryName)' 有什么区别
- php - PHP:读取和写回文件的问题
- android - 如何使用 mockk 库模拟 android 上下文