I saw that <https://github.com/elizarov/Coroutines...
# coroutines
m
I saw that https://github.com/elizarov/CoroutinesMockitoPlayground provides a demo of using Mockito for Kotlin coroutines, in simple cases. But unless I’m mistaken, it’s currently not possible to use Mockito to mock/verify methods with argument matchers. Mockito throws an
InvalidUseOfMatchersException
because the call mixes matches and raw values. This is because the continuation instance in the Java call is always passed directly. Is this correct? Is there any known workaround? I’m currently mocking classes which expose suspending methods manually, but the syntax isn’t very clear. I’d rather use Mockito to keep the tests readable. Example of failing test:
Copy code
interface SuspendingAction {
    suspend fun invoke(any: Any)
}

@Test
fun `verify with mockito`() = runBlocking {
    val mock = Mockito.mock(SuspendingAction::class.java)
    mock.invoke(Any())
    Mockito.verify(mock).invoke(any())
}
Copy code
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
2 matchers expected, 1 recorded: