Skip to content

Instantly share code, notes, and snippets.

@RBusarow
Created July 12, 2019 00:42
Show Gist options
  • Save RBusarow/885dd05309b78d4694afc6650dce384f to your computer and use it in GitHub Desktop.
Save RBusarow/885dd05309b78d4694afc6650dce384f to your computer and use it in GitHub Desktop.
internal class MockkedDispatcherTest {
val dispatcher = TestCoroutineDispatcher()
val scope = TestCoroutineScope(dispatcher)
@Before
fun setUp() {
Dispatchers.setMain(dispatcher)
mockkStatic(Dispatchers::class)
every { Dispatchers.Default } returns dispatcher
every { Dispatchers.Unconfined } returns dispatcher
every { Dispatchers.IO } returns dispatcher
}
@After
fun tearDown() {
unmockkStatic(Dispatchers::class)
Dispatchers.resetMain()
scope.cleanupTestCoroutines()
}
@Test
fun `Dispatchers should always return local dispatcher`() = runBlocking {
withContext(Dispatchers.IO) {
coroutineContext[ContinuationInterceptor] shouldBe dispatcher
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment