private val onApiError: Function1<ApiError, Unit> = mock()
private val apiErrorCaptor: ArgumentCaptor<ApiError> = argumentCaptor()
@Test
fun test() {
verify(onApiError).invoke(capture(apiErrorCaptor)) //<--throws here
}
And got exception:
Caused by: org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
0 matchers expected, 1 recorded:
-> at com.vinted.data.rx.api.ApiObserverTest.testOnThrowedApiError(ApiObserverTest.kt:174)
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.
at java.lang.Throwable.<init>(Throwable.java:311)
at java.lang.Exception.<init>(Exception.java:102)
at java.lang.RuntimeException.<init>(RuntimeException.java:96)
at com.vinted.data.rx.api.ApiError.<init>(ApiError.kt:30)
... 57 more
I checked, ApiError is constructed well using ApiError(Throwable) constructor. Something bad happens with matchers.
For my surprise, #22 fixes that issue. But I don't understand how.
I have class:
Test looks like:
And got exception:
I checked,
ApiError
is constructed well usingApiError(Throwable)
constructor. Something bad happens with matchers.For my surprise, #22 fixes that issue. But I don't understand how.