安装:Springboot withKotlin
产品描述:尝试从一个KotlinJunit测试文件中模拟一个java方法
错误源代码行:
Mockito.`when`(workflowService.sendEvent(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(true)
错误消息:
class kotlin.Unit cannot be cast to class java.lang.Boolean
class kotlin.Unit cannot be cast to class java.lang.Boolean (kotlin.Unit is in unnamed module of loader 'app'; java.lang.Boolean is in module java.base of loader 'bootstrap')
1条答案
按热度按时间ewm0tg9j1#
我的解决方案:使用ArgumentMatchers. any()代替ArgumentMatchers.anyString(),例如:
因为JavaString参数也接受null,所以我们可以使用ArgumentMatchers.any()