32
32
import rx .subjects .PublishSubject ;
33
33
import rx .subscriptions .*;
34
34
35
+ import static org .mockito .Mockito .*;
36
+ import static org .junit .Assert .*;
37
+
35
38
/**
36
39
* Test Completable methods and operators.
37
40
*/
@@ -3469,4 +3472,135 @@ public void endWithFlowableError() {
3469
3472
ts .assertError (TestException .class );
3470
3473
ts .assertNotCompleted ();
3471
3474
}
3475
+
3476
+ @ Test
3477
+ public void usingFactoryThrows () {
3478
+ @ SuppressWarnings ("unchecked" )
3479
+ Action1 <Integer > onDispose = mock (Action1 .class );
3480
+
3481
+ TestSubscriber <Integer > ts = TestSubscriber .create ();
3482
+
3483
+ Completable .using (new Func0 <Integer >() {
3484
+ @ Override
3485
+ public Integer call () {
3486
+ return 1 ;
3487
+ }
3488
+ },
3489
+ new Func1 <Integer , Completable >() {
3490
+ @ Override
3491
+ public Completable call (Integer t ) {
3492
+ throw new TestException ();
3493
+ }
3494
+ }, onDispose ).subscribe (ts );
3495
+
3496
+ verify (onDispose ).call (1 );
3497
+
3498
+ ts .assertNoValues ();
3499
+ ts .assertNotCompleted ();
3500
+ ts .assertError (TestException .class );
3501
+ }
3502
+
3503
+ @ Test
3504
+ public void usingFactoryAndDisposerThrow () {
3505
+ Action1 <Integer > onDispose = new Action1 <Integer >() {
3506
+ @ Override
3507
+ public void call (Integer t ) {
3508
+ throw new TestException ();
3509
+ }
3510
+ };
3511
+
3512
+ TestSubscriber <Integer > ts = TestSubscriber .create ();
3513
+
3514
+ Completable .using (new Func0 <Integer >() {
3515
+ @ Override
3516
+ public Integer call () {
3517
+ return 1 ;
3518
+ }
3519
+ },
3520
+ new Func1 <Integer , Completable >() {
3521
+ @ Override
3522
+ public Completable call (Integer t ) {
3523
+ throw new TestException ();
3524
+ }
3525
+ }, onDispose ).subscribe (ts );
3526
+
3527
+ ts .assertNoValues ();
3528
+ ts .assertNotCompleted ();
3529
+ ts .assertError (CompositeException .class );
3530
+
3531
+ CompositeException ex = (CompositeException )ts .getOnErrorEvents ().get (0 );
3532
+
3533
+ List <Throwable > listEx = ex .getExceptions ();
3534
+
3535
+ assertEquals (2 , listEx .size ());
3536
+
3537
+ assertTrue (listEx .get (0 ).toString (), listEx .get (0 ) instanceof TestException );
3538
+ assertTrue (listEx .get (1 ).toString (), listEx .get (1 ) instanceof TestException );
3539
+ }
3540
+
3541
+ @ Test
3542
+ public void usingFactoryReturnsNull () {
3543
+ @ SuppressWarnings ("unchecked" )
3544
+ Action1 <Integer > onDispose = mock (Action1 .class );
3545
+
3546
+ TestSubscriber <Integer > ts = TestSubscriber .create ();
3547
+
3548
+ Completable .using (new Func0 <Integer >() {
3549
+ @ Override
3550
+ public Integer call () {
3551
+ return 1 ;
3552
+ }
3553
+ },
3554
+ new Func1 <Integer , Completable >() {
3555
+ @ Override
3556
+ public Completable call (Integer t ) {
3557
+ return null ;
3558
+ }
3559
+ }, onDispose ).subscribe (ts );
3560
+
3561
+ verify (onDispose ).call (1 );
3562
+
3563
+ ts .assertNoValues ();
3564
+ ts .assertNotCompleted ();
3565
+ ts .assertError (NullPointerException .class );
3566
+ }
3567
+
3568
+ @ Test
3569
+ public void usingFactoryReturnsNullAndDisposerThrows () {
3570
+ Action1 <Integer > onDispose = new Action1 <Integer >() {
3571
+ @ Override
3572
+ public void call (Integer t ) {
3573
+ throw new TestException ();
3574
+ }
3575
+ };
3576
+
3577
+ TestSubscriber <Integer > ts = TestSubscriber .create ();
3578
+
3579
+ Completable .using (new Func0 <Integer >() {
3580
+ @ Override
3581
+ public Integer call () {
3582
+ return 1 ;
3583
+ }
3584
+ },
3585
+ new Func1 <Integer , Completable >() {
3586
+ @ Override
3587
+ public Completable call (Integer t ) {
3588
+ return null ;
3589
+ }
3590
+ }, onDispose ).subscribe (ts );
3591
+
3592
+ ts .assertNoValues ();
3593
+ ts .assertNotCompleted ();
3594
+ ts .assertError (CompositeException .class );
3595
+
3596
+ CompositeException ex = (CompositeException )ts .getOnErrorEvents ().get (0 );
3597
+
3598
+ List <Throwable > listEx = ex .getExceptions ();
3599
+
3600
+ assertEquals (2 , listEx .size ());
3601
+
3602
+ assertTrue (listEx .get (0 ).toString (), listEx .get (0 ) instanceof NullPointerException );
3603
+ assertTrue (listEx .get (1 ).toString (), listEx .get (1 ) instanceof TestException );
3604
+ }
3605
+
3472
3606
}
0 commit comments