Created
June 2, 2017 14:14
-
-
Save florent37/341c0f56c3e7ecafb61413bd04e55ffd 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
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