Created
March 5, 2017 22:35
-
-
Save timrijckaert/1b07748bf4757fd401493af750925fbc to your computer and use it in GitHub Desktop.
RxJava2 Rule to change the Schedulers to immediate one. (https://www.infoq.com/articles/Testing-RxJava2)
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
private static class ImmediateSchedulersRule implements TestRule { | |
@Override | |
public Statement apply(final Statement base, Description description) { | |
return new Statement() { | |
@Override | |
public void evaluate() throws Throwable { | |
RxJavaPlugins.setIoSchedulerHandler(scheduler -> | |
Schedulers.trampoline()); | |
RxJavaPlugins.setComputationSchedulerHandler(scheduler -> | |
Schedulers.trampoline()); | |
RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> | |
Schedulers.trampoline()); | |
try { | |
base.evaluate(); | |
} finally { | |
RxJavaPlugins.reset(); | |
} | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment