I trying to test a method that have a high order fuction as property, and I'm facing this problem:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at com.nhaarman.mockitokotlin2.KArgumentCaptor.capture(ArgumentCaptor.kt:198)
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.
I'm using argumentCaptor<() -> Unit>()
in another projects, and I don't know why in this app is getting this error.
This is my test
@Test
fun onStart_fetchMovies_failed() {
//Arrange
val captor = argumentCaptor<() -> Unit>()
`when`(movieDataSourceMock.movies(1)).thenReturn(Single.error(RuntimeException(ERROR_MESSAGE)))
//Act
SUT.onStart()
//Assert
verify(viewContractMock).showLoading()
verify(viewContractMock).showMessageError(ERROR_MESSAGE, captor.capture())
verify(viewContractMock).hideLoading()
}