Java 如何解析-指定为非null的参数为null
我有一个单元测试,在这个单元测试中,我试图检查是否使用正确的参数调用了用例,但我得到了一个错误Java 如何解析-指定为非null的参数为null,java,android,kotlin,junit,kotlin-coroutines,Java,Android,Kotlin,Junit,Kotlin Coroutines,我有一个单元测试,在这个单元测试中,我试图检查是否使用正确的参数调用了用例,但我得到了一个错误 java.lang.IllegalArgumentException:指定为非null的参数为null:method com.xx.xxx.clean.orderview.domain.onstanduceCaseCoroutine$Params.,参数serviceType @Test fun `when notifyOnStand is called then we create a Timest
java.lang.IllegalArgumentException:指定为非null的参数为null:method com.xx.xxx.clean.orderview.domain.onstanduceCaseCoroutine$Params.,参数serviceType
@Test
fun `when notifyOnStand is called then we create a TimestampedAction with the correct user id, vehicle, timestamp and pass that to the usecase`() {
val actionCaptor = argumentCaptor<TimestampedAction>()
val timestamp = DateTime.now()
every(noServiceRequiredBus.get()).thenReturn(Observable.just(REQUESTED))
every(timingsUpdater.timestampCalculator(any(), any())).thenReturn(timestamp)
baseOrderViewPresenter.setView(view)
baseOrderViewPresenter.notifyOnStand()
runBlocking {
verify(onStandUseCaseCoroutine).run(OnStandUseCaseCoroutine.Params(any(), any(), capture(actionCaptor)))
}
}
具有用例调用的Presenter层
private fun onstandUseCaseCoroutines(serviceType: String, id: String, action: TimestampedAction, callback: (GenericResponse?) -> Unit) {
try {
onStandUseCaseCoroutine(OnStandUseCaseCoroutine.Params(serviceType, id, action)) {
callback.invoke(it)
}
} catch (exception: Exception) {
onStandResponseErrors()
}
}
请问我该怎么修
我尝试更改为下面的代码,但没有解决它,我不确定如何执行捕获(actionCaptor)
位,如果这是问题所在
runBlocking {
verify(onStandUseCaseCoroutine).run(OnStandUseCaseCoroutine.Params(anyString(), anyString(), capture(actionCaptor)))
}
有什么建议吗
谢谢
R问题源于将空值传递给serviceType字符串参数。尽量不要用任何..隐藏代码。。任何方法以便我们能够找到原因我,当我从
any()
更改为anyString()
时,serviceType
和id
以及capture(actionCaptor)
的错误消失了,我不知道怎么做,就像我没有anyString
@RustamSamandarov谢谢你的回应,你在用mockito吗?
runBlocking {
verify(onStandUseCaseCoroutine).run(OnStandUseCaseCoroutine.Params(anyString(), anyString(), capture(actionCaptor)))
}