@@ -2700,7 +2700,64 @@ public void call(CompletableSubscriber s) {
27002700
27012701 Assert .assertTrue (name .get ().startsWith ("RxComputation" ));
27022702 }
2703-
2703+
2704+ @ Test (timeout = 1000 )
2705+ public void subscribeEmptyOnError () {
2706+ expectUncaughtTestException (new Action0 () {
2707+ @ Override public void call () {
2708+ error .completable .subscribe ();
2709+ }
2710+ });
2711+ }
2712+
2713+ @ Test (timeout = 1000 )
2714+ public void subscribeOneActionOnError () {
2715+ expectUncaughtTestException (new Action0 () {
2716+ @ Override
2717+ public void call () {
2718+ error .completable .subscribe (new Action0 () {
2719+ @ Override
2720+ public void call () {
2721+ }
2722+ });
2723+ }
2724+ });
2725+ }
2726+
2727+ @ Test (timeout = 1000 )
2728+ public void subscribeOneActionThrowFromOnCompleted () {
2729+ expectUncaughtTestException (new Action0 () {
2730+ @ Override
2731+ public void call () {
2732+ normal .completable .subscribe (new Action0 () {
2733+ @ Override
2734+ public void call () {
2735+ throw new TestException ();
2736+ }
2737+ });
2738+ }
2739+ });
2740+ }
2741+
2742+ @ Test (timeout = 1000 )
2743+ public void subscribeTwoActionsThrowFromOnError () {
2744+ expectUncaughtTestException (new Action0 () {
2745+ @ Override
2746+ public void call () {
2747+ error .completable .subscribe (new Action1 <Throwable >() {
2748+ @ Override
2749+ public void call (Throwable throwable ) {
2750+ throw new TestException ();
2751+ }
2752+ }, new Action0 () {
2753+ @ Override
2754+ public void call () {
2755+ }
2756+ });
2757+ }
2758+ });
2759+ }
2760+
27042761 @ Test (timeout = 1000 )
27052762 public void timeoutEmitError () {
27062763 Throwable e = Completable .never ().timeout (100 , TimeUnit .MILLISECONDS ).get ();
@@ -3742,4 +3799,24 @@ public void call(Throwable e) {
37423799 assertNotNull ("Unsubscribed before the call to onError" , subscriptionRef .get ());
37433800 }
37443801
3802+ private static void expectUncaughtTestException (Action0 action ) {
3803+ Thread .UncaughtExceptionHandler originalHandler = Thread .getDefaultUncaughtExceptionHandler ();
3804+ CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler ();
3805+ Thread .setDefaultUncaughtExceptionHandler (handler );
3806+ try {
3807+ action .call ();
3808+ assertEquals ("Should have received exactly 1 exception" , 1 , handler .count );
3809+ Throwable caught = handler .caught ;
3810+ while (caught != null ) {
3811+ if (caught instanceof TestException ) break ;
3812+ if (caught == caught .getCause ()) break ;
3813+ caught = caught .getCause ();
3814+ }
3815+ assertTrue ("A TestException should have been delivered to the handler" ,
3816+ caught instanceof TestException );
3817+ } finally {
3818+ Thread .setDefaultUncaughtExceptionHandler (originalHandler );
3819+ }
3820+ }
3821+
37453822}
0 commit comments