Created
July 7, 2017 09:28
-
-
Save freszu/ef645cd6f704d9e29e19324f61030c30 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
import org.junit.rules.TestRule; | |
import org.junit.runner.Description; | |
import org.junit.runners.model.Statement; | |
import io.reactivex.android.plugins.RxAndroidPlugins; | |
import io.reactivex.plugins.RxJavaPlugins; | |
import io.reactivex.schedulers.Schedulers; | |
public class RxSchedulersOverrideRule implements TestRule { | |
@Override | |
public Statement apply(final Statement base, Description description) { | |
return new Statement() { | |
@Override | |
public void evaluate() throws Throwable { | |
RxAndroidPlugins.setInitMainThreadSchedulerHandler(currentScheduler -> Schedulers.trampoline()); | |
RxJavaPlugins.setComputationSchedulerHandler(currentScheduler -> Schedulers.trampoline()); | |
RxJavaPlugins.setIoSchedulerHandler(currentScheduler -> Schedulers.trampoline()); | |
RxJavaPlugins.setNewThreadSchedulerHandler(currentScheduler -> Schedulers.trampoline()); | |
RxJavaPlugins.setSingleSchedulerHandler(currentScheduler -> Schedulers.trampoline()); | |
base.evaluate(); | |
RxJavaPlugins.reset(); | |
RxAndroidPlugins.reset(); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment