I have a problem with capturing the Class argument via ArgumentCaptor. My test class looks like this:
@RunWith(RobolectricGradleTestRunner::class)
@Config(sd
The return value of classCaptor.capture()
is null, but the signature of IActivityHandler#navigateTo(Class, Boolean)
does not allow a null argument.
The mockito-kotlin library provides supporting functions to solve this problem.
Code should be:
@Captor
lateinit var classCaptor: ArgumentCaptor>
@Captor
lateinit var booleanCaptor: ArgumentCaptor
...
@Test
fun thatNavigatesToAddListScreenOnAddClicked(){
//given
//when
objectUnderTest?.addNewList()
//then
verify(activityHandlerMock).navigateTo(
com.nhaarman.mockitokotlin2.capture>(classCaptor.capture()),
com.nhaarman.mockitokotlin2.capture(booleanCaptor.capture())
)
var clazzValue = classCaptor.value
assertNotNull(clazzValue);
val booleanValue = booleanCaptor.value
assertFalse(booleanValue);
}
OR
var classCaptor = com.nhaarman.mockitokotlin2.argumentCaptor>()
var booleanCaptor = com.nhaarman.mockitokotlin2.argumentCaptor()
...
verify(activityHandlerMock).navigateTo(
classCaptor.capture(),
booleanCaptor.capture()
)
also in build.gradle add this:
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"