jeudi 12 mars 2020

Mockito throws InvalidUseOfMatchersException for "verify()"

I wanted to test the API calls in my application. since the API calls are asynchronous. I am using mockito (verify along with ArgumentCaptor).

@Captor
lateinit var callbackCaptor: ArgumentCaptor<Callback<ResponseModel>>

 @Test
 fun testDetailsApiCall() {
    val mock: MyRepository = mock()
    verify(mock.getSomeDetails("xxx", "xxx", capture(callbackCaptor)))
 }

getSomeDetails inside MyRepository is invoking a server API call and sending the response back via interface callback.

But when I execute this test case I am getting the following error

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
3 matchers expected, 1 recorded:
-> at xxx.xxxx.testDetailsApiCall

This exception may occur if matchers are combined with raw values:
    //incorrect:
    someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
    //correct:
    someMethod(anyObject(), eq("String by matcher"));

For more info see javadoc for Matchers class.

If you guys can figure out the problem in this, it would be really helpful

Aucun commentaire:

Enregistrer un commentaire