Skip to content

Instantly share code, notes, and snippets.

@freszu
Created July 7, 2017 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freszu/ef645cd6f704d9e29e19324f61030c30 to your computer and use it in GitHub Desktop.
Save freszu/ef645cd6f704d9e29e19324f61030c30 to your computer and use it in GitHub Desktop.
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