Skip to content

Instantly share code, notes, and snippets.

@Adam-Fresko
Created February 23, 2017 14:13
Show Gist options
  • Save Adam-Fresko/9f97837bc2ee332e96441a76d21ae55b to your computer and use it in GitHub Desktop.
Save Adam-Fresko/9f97837bc2ee332e96441a76d21ae55b to your computer and use it in GitHub Desktop.
RxJava with RxAndroid example
@Before
public void setUp() throws Exception {
setupRxSchedulers();
}
private void setupRxSchedulers() {
RxJavaHooks.setOnIOScheduler(current -> Schedulers.immediate());
RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() {
@Override
public Scheduler getMainThreadScheduler() {
return Schedulers.immediate(); // witchout this you would have to use wait in tests
}
});
}
@Test
public void testMethod(){
Observable<ArrayList<Object>> placesForLocation = fechObservable();
TestSubscriber<ArrayList<Object>> testSubscriber = new TestSubscriber<>();
placesForLocation.subscribe(testSubscriber);
}
@After
public void tearDown() {
RxAndroidPlugins.getInstance().reset();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment