Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FilipeLipan/eff1e6396a8c210ea651dfb8fa8a3d97 to your computer and use it in GitHub Desktop.
Save FilipeLipan/eff1e6396a8c210ea651dfb8fa8a3d97 to your computer and use it in GitHub Desktop.
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