@@ -3604,4 +3604,142 @@ public Completable call(Integer t) {
3604
3604
assertTrue (listEx .get (1 ).toString (), listEx .get (1 ) instanceof TestException );
3605
3605
}
3606
3606
3607
+ @ Test
3608
+ public void subscribeReportsUnsubscribed () {
3609
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3610
+ Completable completable = stringSubject .toCompletable ();
3611
+
3612
+ Subscription completableSubscription = completable .subscribe ();
3613
+
3614
+ stringSubject .onCompleted ();
3615
+
3616
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3617
+ }
3618
+
3619
+ @ Test
3620
+ public void subscribeReportsUnsubscribedOnError () {
3621
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3622
+ Completable completable = stringSubject .toCompletable ();
3623
+
3624
+ Subscription completableSubscription = completable .subscribe ();
3625
+
3626
+ stringSubject .onError (new TestException ());
3627
+
3628
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3629
+ }
3630
+
3631
+ @ Test
3632
+ public void subscribeActionReportsUnsubscribed () {
3633
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3634
+ Completable completable = stringSubject .toCompletable ();
3635
+
3636
+ Subscription completableSubscription = completable .subscribe (Actions .empty ());
3637
+
3638
+ stringSubject .onCompleted ();
3639
+
3640
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3641
+ }
3642
+
3643
+ @ Test
3644
+ public void subscribeActionReportsUnsubscribedAfter () {
3645
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3646
+ Completable completable = stringSubject .toCompletable ();
3647
+
3648
+ final AtomicReference <Subscription > subscriptionRef = new AtomicReference <Subscription >();
3649
+ Subscription completableSubscription = completable .subscribe (new Action0 () {
3650
+ @ Override
3651
+ public void call () {
3652
+ if (subscriptionRef .get ().isUnsubscribed ()) {
3653
+ subscriptionRef .set (null );
3654
+ }
3655
+ }
3656
+ });
3657
+ subscriptionRef .set (completableSubscription );
3658
+
3659
+ stringSubject .onCompleted ();
3660
+
3661
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3662
+ assertNotNull ("Unsubscribed before the call to onCompleted" , subscriptionRef .get ());
3663
+ }
3664
+
3665
+ @ Test
3666
+ public void subscribeActionReportsUnsubscribedOnError () {
3667
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3668
+ Completable completable = stringSubject .toCompletable ();
3669
+
3670
+ Subscription completableSubscription = completable .subscribe (Actions .empty ());
3671
+
3672
+ stringSubject .onError (new TestException ());
3673
+
3674
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3675
+ }
3676
+
3677
+ @ Test
3678
+ public void subscribeAction2ReportsUnsubscribed () {
3679
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3680
+ Completable completable = stringSubject .toCompletable ();
3681
+
3682
+ Subscription completableSubscription = completable .subscribe (Actions .empty (), Actions .empty ());
3683
+
3684
+ stringSubject .onCompleted ();
3685
+
3686
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3687
+ }
3688
+
3689
+ @ Test
3690
+ public void subscribeAction2ReportsUnsubscribedOnError () {
3691
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3692
+ Completable completable = stringSubject .toCompletable ();
3693
+
3694
+ Subscription completableSubscription = completable .subscribe (Actions .empty (), Actions .empty ());
3695
+
3696
+ stringSubject .onError (new TestException ());
3697
+
3698
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3699
+ }
3700
+
3701
+ @ Test
3702
+ public void subscribeAction2ReportsUnsubscribedAfter () {
3703
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3704
+ Completable completable = stringSubject .toCompletable ();
3705
+
3706
+ final AtomicReference <Subscription > subscriptionRef = new AtomicReference <Subscription >();
3707
+ Subscription completableSubscription = completable .subscribe (Actions .empty (), new Action0 () {
3708
+ @ Override
3709
+ public void call () {
3710
+ if (subscriptionRef .get ().isUnsubscribed ()) {
3711
+ subscriptionRef .set (null );
3712
+ }
3713
+ }
3714
+ });
3715
+ subscriptionRef .set (completableSubscription );
3716
+
3717
+ stringSubject .onCompleted ();
3718
+
3719
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3720
+ assertNotNull ("Unsubscribed before the call to onCompleted" , subscriptionRef .get ());
3721
+ }
3722
+
3723
+ @ Test
3724
+ public void subscribeAction2ReportsUnsubscribedOnErrorAfter () {
3725
+ PublishSubject <String > stringSubject = PublishSubject .create ();
3726
+ Completable completable = stringSubject .toCompletable ();
3727
+
3728
+ final AtomicReference <Subscription > subscriptionRef = new AtomicReference <Subscription >();
3729
+ Subscription completableSubscription = completable .subscribe (new Action1 <Throwable >() {
3730
+ @ Override
3731
+ public void call (Throwable e ) {
3732
+ if (subscriptionRef .get ().isUnsubscribed ()) {
3733
+ subscriptionRef .set (null );
3734
+ }
3735
+ }
3736
+ }, Actions .empty ());
3737
+ subscriptionRef .set (completableSubscription );
3738
+
3739
+ stringSubject .onError (new TestException ());
3740
+
3741
+ assertTrue ("Not unsubscribed?" , completableSubscription .isUnsubscribed ());
3742
+ assertNotNull ("Unsubscribed before the call to onError" , subscriptionRef .get ());
3743
+ }
3744
+
3607
3745
}
0 commit comments