Created
June 16, 2020 19:14
-
-
Save FilipeLipan/eff1e6396a8c210ea651dfb8fa8a3d97 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
class TestSchedulerRule : TestRule { | |
val testScheduler = TestScheduler() | |
@Suppress("UNUSED_ANONYMOUS_PARAMETER") | |
override fun apply(base: Statement, d: Description): Statement { | |
return object : Statement() { | |
@Throws(Throwable::class) | |
override fun evaluate() { | |
RxJavaPlugins.setIoSchedulerHandler { scheduler -> testScheduler } | |
RxJavaPlugins.setComputationSchedulerHandler { scheduler -> testScheduler } | |
RxJavaPlugins.setNewThreadSchedulerHandler { scheduler -> testScheduler } | |
RxAndroidPlugins.setMainThreadSchedulerHandler { scheduler -> Schedulers.trampoline() } | |
RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler -> Schedulers.trampoline() } | |
try { | |
base.evaluate() | |
} finally { | |
RxJavaPlugins.reset() | |
RxAndroidPlugins.reset() | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment