Created
July 12, 2019 00:42
-
-
Save RBusarow/885dd05309b78d4694afc6650dce384f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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