|
23 | 23 | import org.junit.*;
|
24 | 24 |
|
25 | 25 | import rx.Completable.*;
|
| 26 | +import rx.Observable.OnSubscribe; |
26 | 27 | import rx.exceptions.*;
|
27 | 28 | import rx.functions.*;
|
28 | 29 | import rx.observers.TestSubscriber;
|
@@ -357,6 +358,64 @@ public void call(Long v) {
|
357 | 358 | Assert.assertEquals(Arrays.asList(5L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), requested);
|
358 | 359 | }
|
359 | 360 |
|
| 361 | + @Test |
| 362 | + public void andThen() { |
| 363 | + TestSubscriber<String> ts = new TestSubscriber<String>(0); |
| 364 | + Completable.complete().andThen(Observable.just("foo")).subscribe(ts); |
| 365 | + ts.requestMore(1); |
| 366 | + ts.assertValue("foo"); |
| 367 | + ts.assertCompleted(); |
| 368 | + ts.assertNoErrors(); |
| 369 | + } |
| 370 | + |
| 371 | + @Test |
| 372 | + public void andThenNever() { |
| 373 | + TestSubscriber<String> ts = new TestSubscriber<String>(0); |
| 374 | + Completable.never().andThen(Observable.just("foo")).subscribe(ts); |
| 375 | + ts.requestMore(1); |
| 376 | + ts.assertNoValues(); |
| 377 | + ts.assertNoTerminalEvent(); |
| 378 | + } |
| 379 | + |
| 380 | + @Test |
| 381 | + public void andThenError() { |
| 382 | + TestSubscriber<String> ts = new TestSubscriber<String>(0); |
| 383 | + final AtomicBoolean hasRun = new AtomicBoolean(false); |
| 384 | + final Exception e = new Exception(); |
| 385 | + Completable.create(new CompletableOnSubscribe() { |
| 386 | + @Override |
| 387 | + public void call(CompletableSubscriber cs) { |
| 388 | + cs.onError(e); |
| 389 | + } |
| 390 | + }) |
| 391 | + .andThen(Observable.<String>create(new OnSubscribe<String>() { |
| 392 | + @Override |
| 393 | + public void call(Subscriber<? super String> s) { |
| 394 | + hasRun.set(true); |
| 395 | + s.onNext("foo"); |
| 396 | + s.onCompleted(); |
| 397 | + } |
| 398 | + })) |
| 399 | + .subscribe(ts); |
| 400 | + ts.assertNoValues(); |
| 401 | + ts.assertError(e); |
| 402 | + Assert.assertFalse("Should not have subscribed to observable when completable errors", hasRun.get()); |
| 403 | + } |
| 404 | + |
| 405 | + @Test |
| 406 | + public void andThenSubscribeOn() { |
| 407 | + TestSubscriber<String> ts = new TestSubscriber<String>(0); |
| 408 | + TestScheduler scheduler = new TestScheduler(); |
| 409 | + Completable.complete().andThen(Observable.just("foo").delay(1, TimeUnit.SECONDS, scheduler)).subscribe(ts); |
| 410 | + ts.requestMore(1); |
| 411 | + ts.assertNoValues(); |
| 412 | + ts.assertNoTerminalEvent(); |
| 413 | + scheduler.advanceTimeBy(1, TimeUnit.SECONDS); |
| 414 | + ts.assertValue("foo"); |
| 415 | + ts.assertCompleted(); |
| 416 | + ts.assertNoErrors(); |
| 417 | + } |
| 418 | + |
360 | 419 | @Test(expected = NullPointerException.class)
|
361 | 420 | public void createNull() {
|
362 | 421 | Completable.create(null);
|
|
0 commit comments