Daniele Segato
01/22/2021, 10:13 AMCoroutineScope
/ CoroutineContext
?
I would I unit test this function?
fun createCoroutineScope(): CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
So in my test I have to check if the returned CoroutineScope
is using a SupervisedJob
or a particular Dispatcher
how do I do that??
(or any other property of the context/scope)diesieben07
01/22/2021, 10:18 AMCoroutineContext
is basically a type-safe map, the keys are CoroutineContext.Key
.
In your example scope.coroutineContext[Job]
would give you the SupervisorJob
(because Job
has a companion object
which is the CoroutineContext.Key
); scope.coroutineContext[CoroutineDispatcher]
will give you Dispatchers.Default
in the same way.Daniele Segato
01/22/2021, 10:19 AMdiesieben07
01/22/2021, 10:20 AMCtrl-H
) on CoroutineContext.Key
does it for me. I can't find that in the menus though, I always just use the shortcut 😄Daniele Segato
01/22/2021, 12:00 PMCtrl+Shift+A
and look for type hierarchyscope.coroutineContext[Job]
but than I do not know how to check it's a SupervisorJob.
it's not a class, it's a top level function and the implementation is private