Created
June 2, 2017 11:27
-
-
Save McGalanes/b54d730bda3a17a38ede7c263e36dbdb to your computer and use it in GitHub Desktop.
Needed for Tests with RxJava Schedulers
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.plugins.RxJavaPlugins; | |
import io.reactivex.schedulers.Schedulers; | |
public 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