20
20
import org .mockito .InOrder ;
21
21
import org .mockito .Mock ;
22
22
import org .mockito .MockitoAnnotations ;
23
+
23
24
import rx .Observable ;
24
25
import rx .Observable .OnSubscribe ;
25
26
import rx .Observer ;
26
27
import rx .Subscriber ;
27
28
import rx .exceptions .CompositeException ;
28
29
import rx .exceptions .TestException ;
30
+ import rx .observers .TestSubscriber ;
29
31
30
32
import java .util .ArrayList ;
31
33
import java .util .List ;
32
34
import java .util .concurrent .CountDownLatch ;
35
+ import java .util .concurrent .TimeUnit ;
33
36
34
37
import static org .junit .Assert .*;
35
38
import static org .mockito .Matchers .any ;
@@ -475,4 +478,51 @@ public void onCompleted() {
475
478
inOrder .verify (o ).onError (any (TestException .class ));
476
479
verify (o , never ()).onCompleted ();
477
480
}
478
- }
481
+
482
+ @ Test
483
+ public void testErrorInParentObservableDelayed () throws Exception {
484
+ final TestASynchronous1sDelayedObservable o1 = new TestASynchronous1sDelayedObservable ();
485
+ final TestASynchronous1sDelayedObservable o2 = new TestASynchronous1sDelayedObservable ();
486
+ Observable <Observable <String >> parentObservable = Observable .create (new Observable .OnSubscribe <Observable <String >>() {
487
+ @ Override
488
+ public void call (Subscriber <? super Observable <String >> op ) {
489
+ op .onNext (Observable .create (o1 ));
490
+ op .onNext (Observable .create (o2 ));
491
+ op .onError (new NullPointerException ("throwing exception in parent" ));
492
+ }
493
+ });
494
+
495
+ TestSubscriber <String > ts = new TestSubscriber <String >(stringObserver );
496
+ Observable <String > m = Observable .mergeDelayError (parentObservable );
497
+ m .subscribe (ts );
498
+ ts .awaitTerminalEvent (2000 , TimeUnit .MILLISECONDS );
499
+ ts .assertTerminalEvent ();
500
+
501
+ verify (stringObserver , times (2 )).onNext ("hello" );
502
+ verify (stringObserver , times (1 )).onError (any (NullPointerException .class ));
503
+ verify (stringObserver , never ()).onCompleted ();
504
+ }
505
+
506
+ private static class TestASynchronous1sDelayedObservable implements Observable .OnSubscribe <String > {
507
+ Thread t ;
508
+
509
+ @ Override
510
+ public void call (final Subscriber <? super String > observer ) {
511
+ t = new Thread (new Runnable () {
512
+
513
+ @ Override
514
+ public void run () {
515
+ try {
516
+ Thread .sleep (100 );
517
+ } catch (InterruptedException e ) {
518
+ observer .onError (e );
519
+ }
520
+ observer .onNext ("hello" );
521
+ observer .onCompleted ();
522
+ }
523
+
524
+ });
525
+ t .start ();
526
+ }
527
+ }
528
+ }
0 commit comments