Created
October 28, 2016 09:39
-
-
Save florent37/588ef9482ea0df2e11025472f516e5a4 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
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