Skip to content

Instantly share code, notes, and snippets.

@florent37
Created June 2, 2017 14:14
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 florent37/341c0f56c3e7ecafb61413bd04e55ffd to your computer and use it in GitHub Desktop.
Save florent37/341c0f56c3e7ecafb61413bd04e55ffd 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.Scheduler;
import io.reactivex.android.plugins.RxAndroidPlugins;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
public class RxJavaSchedulersTestRule2 implements TestRule {
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
resetPlugins();
RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(@NonNull Scheduler scheduler) throws Exception {
return Schedulers.trampoline();
}
});
RxAndroidPlugins.setMainThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(@NonNull Scheduler scheduler) throws Exception {
return Schedulers.trampoline();
}
});
base.evaluate();
resetPlugins();
}
};
}
private void resetPlugins() {
RxJavaPlugins.reset();
RxAndroidPlugins.reset();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment