Created
June 22, 2018 04:27
-
-
Save guodong1111/9dfedd14f2c74cef10dea2b733e4c7a8 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 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