So far I have ```runBlockingTest { whe...
# coroutines
m
So far I have
Copy code
runBlockingTest {
            whenever(model.loadData(false)).thenThrow(DeprecatedApiException())
t
Try with
whenever(model.loadData(eq(false))).thenThrow(DeprecatedApiException())
When stubbing a function with parameters, you need to wrap expected parameters in
eq(...)
, that's a Mockito trick. Tell me if that solved the problem !
m
@tseisel when I enter the code you posted, I get:
Copy code
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at com.nhaarman.mockito_kotlin.MockitoKt.eq(Mockito.kt:114)

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.
the suspend function I’m mocking only takes one argument, though…
t
When compiled,
suspend
functions are translated to a regular function with an additional
Continuation
parameter. Older Mockito versions are not aware of that and therefore are unable to properly mock suspending functions. Suspend functions are supported from version 2.23, check if the version you use is 2.23 or newer