24
24
import org .robolectric .annotation .Config ;
25
25
import rx .Observable ;
26
26
import rx .Subscriber ;
27
+ import rx .Subscription ;
27
28
import rx .observers .TestSubscriber ;
28
29
29
30
import static org .junit .Assert .assertFalse ;
31
+ import static org .junit .Assert .assertTrue ;
30
32
import static org .mockito .Matchers .any ;
31
- import static org .mockito .Mockito .never ;
32
- import static org .mockito .Mockito .verify ;
33
- import static org .mockito .Mockito .verifyZeroInteractions ;
33
+ import static org .mockito .Mockito .*;
34
34
35
35
@ RunWith (RobolectricTestRunner .class )
36
36
@ Config (manifest = Config .NONE )
@@ -45,14 +45,34 @@ public void setup() {
45
45
}
46
46
47
47
@ Test
48
- public void testDoesNotComplete () {
49
- Observable .never ()
50
- .lift (new OperatorSubscribeUntil <Object , String >(Observable .just ("Single Item" )))
48
+ public void testSourceUnsubscribesOnNext () {
49
+ Subscription subscription = Observable .never ()
50
+ .lift (new OperatorSubscribeUntil <Object , Object >(Observable .just (new Object () )))
51
51
.subscribe (subscriber );
52
52
53
53
verify (subscriber , never ()).onNext (any ());
54
- verify (subscriber , never ()).onError (any (Throwable .class ));
54
+ assertTrue (subscription .isUnsubscribed ());
55
+ }
56
+
57
+ @ Test
58
+ public void testSourceUnsubscribesOnComplete () {
59
+ Subscription subscription = Observable .never ()
60
+ .lift (new OperatorSubscribeUntil <Object , Object >(Observable .empty ()))
61
+ .subscribe (subscriber );
62
+
55
63
verify (subscriber , never ()).onCompleted ();
64
+ assertTrue (subscription .isUnsubscribed ());
65
+ }
66
+
67
+ @ Test
68
+ public void testSourceReceivesExceptions () {
69
+ Exception exception = new RuntimeException ();
70
+ Subscription subscription = Observable .never ()
71
+ .lift (new OperatorSubscribeUntil <Object , String >(Observable .<String >error (exception )))
72
+ .subscribe (subscriber );
73
+
74
+ verify (subscriber , atLeastOnce ()).onError (exception );
75
+ assertTrue (subscription .isUnsubscribed ());
56
76
}
57
77
58
78
}
0 commit comments