Created
May 2, 2020 15:53
-
-
Save pranay1494/053f40a3a8c307479a81bdaea2300b57 to your computer and use it in GitHub Desktop.
This file contains 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
package olx.com.delorean.view.filter.viewmodel | |
import kotlinx.coroutines.CoroutineDispatcher | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.test.TestCoroutineDispatcher | |
import kotlinx.coroutines.test.TestCoroutineScope | |
import kotlinx.coroutines.test.resetMain | |
import kotlinx.coroutines.test.setMain | |
import org.junit.rules.TestWatcher | |
import org.junit.runner.Description | |
import kotlin.coroutines.ContinuationInterceptor | |
class CoroutineDispatcherRule : TestWatcher(), TestCoroutineScope by TestCoroutineScope() { | |
val testDispatcher = TestCoroutineDispatcher() | |
override fun finished(description: Description?) { | |
super.finished(description) | |
Dispatchers.resetMain() | |
testDispatcher.cleanupTestCoroutines() | |
} | |
override fun starting(description: Description?) { | |
super.starting(description) | |
Dispatchers.setMain(this.coroutineContext[ContinuationInterceptor] as CoroutineDispatcher) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment