Created
May 22, 2021 06:16
-
-
Save seoft/3f0eb9f096ce04840e485e6d7eaa7b13 to your computer and use it in GitHub Desktop.
RxSchedulerRule.kt
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
import io.reactivex.android.plugins.RxAndroidPlugins | |
import io.reactivex.plugins.RxJavaPlugins | |
import io.reactivex.schedulers.Schedulers | |
import org.junit.rules.TestRule | |
import org.junit.runner.Description | |
import org.junit.runners.model.Statement | |
class RxSchedulerRule : TestRule { | |
override fun apply(base: Statement?, description: Description?): Statement { | |
return object : Statement() { | |
@Throws(Throwable::class) | |
override fun evaluate() { | |
RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() } | |
RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() } | |
RxJavaPlugins.setNewThreadSchedulerHandler { Schedulers.trampoline() } | |
RxJavaPlugins.setSingleSchedulerHandler { Schedulers.trampoline() } | |
RxAndroidPlugins.setInitMainThreadSchedulerHandler { 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