如何解决java.lang.IllegalStateException:使用kotlin时ArgumentMatchers.any()不得为null

大家好,我收到错误java.lang.IllegalStateException:ArgumentMatchers.any()在kotlin中不能为null。下面是我所做的代码。请您检查我做错了什么。在Java的情况下可以使用。

@RunWith(MockitoJUnitRunner::class)
class HelpDeskPresenterTest {
    @Mock
    private lateinit var mockAPIManger:APIManger
    @Mock
    private lateinit var applicationData: ApplicationData
    @Mock
    private lateinit var mockInfo:Info
    @Mock
    private lateinit var mockSucessResponse:SuccessResponse
    @Mock
    private lateinit var mockPayResponse:=PayLoadResponse
    @Mock
    private lateinit var mockView: Presenter.View
    @InjectMocks
    private lateinit var presenter:DeskPresenter
    private val name = “Name”

    @Before
    fun setUp() {
        presenter = DeskPresenter(mockAPIManger,applicationData)
        presenter.attachView(mockView, Bundle())
        `when`(mockSucessResponse.payload).thenReturn(mockSucessResponse)
        `when`(applicationData.selectedData).thenReturn(mockInfo)
        `when`(mockInfo.name).thenReturn(name)
    }

    @Test
    fun test_getResponse_when_DeskPresenterAPI_is_success() {
        `when`(
                APIManger.getMapDetails(
                        ArgumentMatchers.anyString(),
                        ArgumentMatchers.any())).then { invocation ->
            val callback: BaseCallback<SuccessResponse> =
                    invocation.getArgument(1) as BaseCallback<SuccessResponse>
            callback.onSuccess(mockSucessResponse)
            callback.onComplete()
        }
        // when
        presenter.getDynamicResponse()
        // then
        verify(mockView, times(1)).showProgressDialog()
        verify(mockView, times(1)).hideProgressDialog()
        verify(mockView, times(1)).fetchMapData(mockPayResponse)
    }

 }
评论