Skip to content

Instantly share code, notes, and snippets.

@guodong1111
Created June 22, 2018 04:27
Show Gist options
  • Save guodong1111/9dfedd14f2c74cef10dea2b733e4c7a8 to your computer and use it in GitHub Desktop.
Save guodong1111/9dfedd14f2c74cef10dea2b733e4c7a8 to your computer and use it in GitHub Desktop.
package net.ettoday.phone.utils
import io.reactivex.plugins.RxJavaPlugins
import io.reactivex.android.plugins.RxAndroidPlugins
import io.reactivex.schedulers.Schedulers
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
class RxSchedulerRule : TestRule {
companion object {
private val SCHEDULER_INSTANCE = Schedulers.trampoline()
}
override fun apply(base: Statement, description: Description): Statement {
return object : Statement() {
@Throws(Throwable::class)
override fun evaluate() {
RxAndroidPlugins.reset()
RxAndroidPlugins.setInitMainThreadSchedulerHandler{
SCHEDULER_INSTANCE
}
RxJavaPlugins.reset()
RxJavaPlugins.setIoSchedulerHandler {
SCHEDULER_INSTANCE
}
RxJavaPlugins.setNewThreadSchedulerHandler {
SCHEDULER_INSTANCE
}
RxJavaPlugins.setComputationSchedulerHandler {
SCHEDULER_INSTANCE
}
base.evaluate()
RxAndroidPlugins.reset()
RxJavaPlugins.reset()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment