Skip to content

Instantly share code, notes, and snippets.

@florent37
Created October 28, 2016 09:39
Show Gist options
  • Save florent37/588ef9482ea0df2e11025472f516e5a4 to your computer and use it in GitHub Desktop.
Save florent37/588ef9482ea0df2e11025472f516e5a4 to your computer and use it in GitHub Desktop.
public class RxJavaSchedulersTestRule implements TestRule {
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
resetPlugins();
RxJavaPlugins.getInstance().registerSchedulersHook(new TestRxJavaSchedulersHook());
RxAndroidPlugins.getInstance().registerSchedulersHook(new TestRxAndroidSchedulersHook());
base.evaluate();
resetPlugins();
}
};
}
private void resetPlugins() {
RxJavaPlugins.getInstance().reset();
RxAndroidPlugins.getInstance().reset();
}
private class TestRxAndroidSchedulersHook extends RxAndroidSchedulersHook {
@Override
public Scheduler getMainThreadScheduler() {
return Schedulers.immediate();
}
}
private class TestRxJavaSchedulersHook extends RxJavaSchedulersHook {
@Override
public Scheduler getIOScheduler() {
return Schedulers.immediate();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment