Created
February 8, 2016 07:30
-
-
Save MyDogTom/2783b55427ecfc4e810d to your computer and use it in GitHub Desktop.
test rule for rxSchedulersHook
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
package rx.plugins; | |
import rx.Scheduler; | |
import rx.android.plugins.RxAndroidSchedulersHook; | |
import rx.schedulers.Schedulers; | |
/** | |
* Created by ata on 07.02.2016. | |
*/ | |
public class AndroidSchedulersHook extends RxAndroidSchedulersHook { | |
@Override | |
public Scheduler getMainThreadScheduler() { | |
return Schedulers.immediate(); | |
} | |
} |
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
package rx.plugins; | |
import org.junit.rules.TestRule; | |
import org.junit.runner.Description; | |
import org.junit.runners.model.Statement; | |
import rx.android.plugins.RxAndroidPlugins; | |
/** | |
* Created by Chatchenko.S on 2/5/2016. | |
*/ | |
public class RxJavaResetRule implements TestRule { | |
@Override | |
public Statement apply(Statement base, Description description) { | |
return new Statement() { | |
@Override | |
public void evaluate() throws Throwable { | |
//before: plugins reset, execution and schedulers hook defined | |
RxJavaPlugins.getInstance().reset(); | |
RxAndroidPlugins.getInstance().reset(); | |
RxJavaPlugins.getInstance().registerSchedulersHook(new SchedulersHook()); | |
RxAndroidPlugins.getInstance().registerSchedulersHook(new AndroidSchedulersHook()); | |
base.evaluate(); | |
//after: clean up | |
RxJavaPlugins.getInstance().reset(); | |
RxAndroidPlugins.getInstance().reset(); | |
} | |
}; | |
} | |
} |
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
package rx.plugins; | |
import rx.Scheduler; | |
import rx.schedulers.Schedulers; | |
/** | |
* Created by ata on 07.02.2016. | |
*/ | |
public class SchedulersHook extends RxJavaSchedulersHook { | |
@Override | |
public Scheduler getIOScheduler() { | |
return Schedulers.immediate(); | |
} | |
@Override | |
public Scheduler getNewThreadScheduler() { | |
return Schedulers.immediate(); | |
} | |
@Override | |
public Scheduler getComputationScheduler() { | |
return Schedulers.immediate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment