Skip to content

Instantly share code, notes, and snippets.

@mootoh
Last active February 19, 2016 09:01
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 mootoh/47fd79c088ffc191b562 to your computer and use it in GitHub Desktop.
Save mootoh/47fd79c088ffc191b562 to your computer and use it in GitHub Desktop.
public class ApplicationTest extends ApplicationTestCase<Application> {
private static final String TAG = "Test";
public ApplicationTest() {
super(Application.class);
}
public void testRxSample() throws InterruptedException {
final CountDownLatch signal = new CountDownLatch(1);
final String[] last = new String[1];
Observable.just("one", "two", "three", "four", "five")
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<String>() {
@Override
public void onCompleted() {
Log.d(TAG, "completed");
signal.countDown();
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String s) {
Log.d(TAG, "onNext: " + s);
last[0] = s;
}
})
;
signal.await(5, TimeUnit.SECONDS);
assertEquals("five", last[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment