Daniele Segato
01/22/2021, 4:54 PMfun 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)
For instance, say I wanna write an unit test that force me to create a CoroutineScope(SupervisorJob())
@Test
fun createCoroutineScope_produce_a_supervisor_job() {
val scope = createCoroutineScope()
val job = scope.coroutineContext[Job]
assertTrue(job is SupervisorJob) // can't do
}
SupervisorJob
is not an interface or a class, it's a top level function. It's implementation tells me nothing about what kind of job it is or how it handle children. The implementation is private.
I cannot find a way to force me to write that code from an unit test, can anyone enlighten me?
(I've asked this in #getting-started but I realized it is better suited here + I asked it better here)