2

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()
}
Wellington Yogui
  • 371
  • 3
  • 18
  • As I can see error raises on `showMessageError` verifying. Can you say what `ERROR_MESSAGE` and `captor.capture()` are? – Ircover Dec 12 '19 at 10:08
  • You can not mix `Matchers` and normal values. Try using `Mockito.eq(ERROR_MESSAGE)` instead. – second Dec 12 '19 at 12:22

0 Answers0