<@UBVUPTGTS> have you tried verifying the 2nd argu...
# coroutines
b
@Martin Devillers have you tried verifying the 2nd argument passed is a
Continuation
?
m
How would I do that?
b
use a matcher that specifies it should be an instance of a
Continuation
(I’m not sure what the matcher is called, I don’t have a project using Mockito right now) Something along the lines of
Copy code
Mockito.verify(mock).invoke(any(), instanceOf(Continuation::class.java))
m
I don’t know that there’s any way to pass the continuation argument for a suspending function explicitly. AFAIK it’s all managed by the compiler. That’s essentially the magic of coroutines.
b
You don’t need to.
runBlocking
is executing the block as a coroutine. The compiler will automatically pass the Continuation. You just need to verify it was passed. I looked up the matcher as well:
Copy code
Mockito.verify(mock).invoke(any(), any(Continuation::class.java))
https://static.javadoc.io/org.mockito/mockito-core/2.21.0/org/mockito/ArgumentMatchers.html#any-java.lang.Class-
m
The compiler won’t let you write that, because in that code
invoke
is the method on the instance, which doesn’t have a
Continuation
instance visible within Kotlin. It’s added by the compiler.
b
Does
Mockito.verify(mock)
return
SuspendingAction
as a proxy? I’m not very familiar with Mockito specifically
m
public static <T> T verify(T mock)
it returns an instance of the class being verified, which is actually the mock itself decorated in order to perform assertions on it. You then call the instance methods on it, and Mockito verifies that they were also called on the mock itself.
b
Ahh. This would be outside the area that I can help 🙂. My GUESS would be something to with the
any()
matcher and instantiating an instance of
Any()
directly 🤷 best of luck on it though!
m
Thanks for trying!
g
@bdawg.io I havent tried this but my understanding of mockito's architecture implies that it might work:
Copy code
val verifier = Mockito.verify(mock)
val arg1Ignored = any(firstArgType::class)
val arg2Ignored = any(Continuation::class)
verifier.invoke(arg1Ignored)
to my knowledge this is because mockito uses a static stack behind the scenes to track argument matchers and invocations. In this way, we're tricking that system into effectivly pushing an extra argument matcher for
Continuation
onto the stack. IIRC the actual value passed into the method invocation is erroneous
er... no its going to complain about mixing-and-matching live with matcher arguments isnt it... damn.
m
😖