How do I test methods with high order function parameter?

Viewed 106

I'm trying to test a method with a high order function as parameter. And facing this error:

Argument(s) are different! Wanted:
viewContractMock.showError(
    (fetchUserIdentity_showOptions_failed$2) Function0<kotlin.Unit>
);
-> at br.com.fastshop.ecommerce.ui.resetpassword.controller.RecoveryOptionsControllerTest.fetchUserIdentity_showOptions_failed(RecoveryOptionsControllerTest.kt:65)
Actual invocation has different arguments:
viewContractMock.showError(
    () Function0<kotlin.Unit>
);
-> at br.com.fastshop.ecommerce.ui.resetpassword.controller.RecoveryOptionsController$observeLive$2.onChanged(RecoveryOptionsController.kt:29)

Apparently I'm not passing the right parameter when I call the showError method

This is my fun test:

    @Test
fun fetchUserIdentity_showOptions_failed() {
    //Arrange
    `when`(guestIdentityDataSourceMock.userInfo()).thenReturn(Completable.error { RuntimeException("") })
    //Act
    SUT.onStart()
    //Assert
    verify(viewContractMock).showLoading()
    verify(viewContractMock).hideLoading()
    verify(viewContractMock).showError { fetchUserIdentity_showOptions_failed() }
}

And here is where my methods are called from application:

        recoveryOptionsUseCase.userIdentityLive.observe({ lifecycle }) {
        when (it.status) {
            ResourceState.LOADING -> {
                if (it.loading) {
                    viewContract.showLoading()
                } else {
                    viewContract.hideLoading()
                }
            }
            ResourceState.SUCCESS -> {
                viewContract.bindOptions()
            }
            ResourceState.ERROR -> viewContract.showError(it.callback!!)
        }
    }
0 Answers
Related