https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

mdapp

06/05/2019, 5:51 PM
So far I have
Copy code
runBlockingTest {
            whenever(model.loadData(false)).thenThrow(DeprecatedApiException())
t

tseisel

06/06/2019, 6:24 AM
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

mdapp

06/11/2019, 9:01 PM
@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

tseisel

06/12/2019, 6:18 AM
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
9 Views