|
27 | 27 | import org.junit.Before;
|
28 | 28 | import org.junit.Test;
|
29 | 29 | import org.mockito.Mock;
|
30 |
| -import org.mockito.Mockito; |
31 | 30 | import org.mockito.MockitoAnnotations;
|
32 | 31 |
|
33 | 32 | import rx.Observable.OnSubscribeFunc;
|
@@ -69,10 +68,47 @@ public Subscription onSubscribe(Observer<? super String> Observer) {
|
69 | 68 | verify(aObserver, times(1)).onNext("one");
|
70 | 69 | verify(aObserver, times(1)).onNext("two");
|
71 | 70 | verify(aObserver, times(1)).onNext("three");
|
72 |
| - verify(aObserver, Mockito.never()).onError(any(Throwable.class)); |
| 71 | + verify(aObserver, never()).onError(any(Throwable.class)); |
73 | 72 | verify(aObserver, times(1)).onCompleted();
|
74 | 73 | }
|
75 | 74 |
|
| 75 | + @Test |
| 76 | + public void testCountAFewItems() { |
| 77 | + Observable<String> observable = Observable.from("a", "b", "c", "d"); |
| 78 | + observable.count().subscribe(w); |
| 79 | + // we should be called only once |
| 80 | + verify(w, times(1)).onNext(anyInt()); |
| 81 | + verify(w).onNext(4); |
| 82 | + verify(w, never()).onError(any(Throwable.class)); |
| 83 | + verify(w, times(1)).onCompleted(); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testCountZeroItems() { |
| 88 | + Observable<String> observable = Observable.empty(); |
| 89 | + observable.count().subscribe(w); |
| 90 | + // we should be called only once |
| 91 | + verify(w, times(1)).onNext(anyInt()); |
| 92 | + verify(w).onNext(0); |
| 93 | + verify(w, never()).onError(any(Throwable.class)); |
| 94 | + verify(w, times(1)).onCompleted(); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testCountError() { |
| 99 | + Observable<String> o = Observable.create(new OnSubscribeFunc<String>() { |
| 100 | + @Override |
| 101 | + public Subscription onSubscribe(Observer<? super String> obsv) { |
| 102 | + obsv.onError(new RuntimeException()); |
| 103 | + return Subscriptions.empty(); |
| 104 | + } |
| 105 | + }); |
| 106 | + o.count().subscribe(w); |
| 107 | + verify(w, never()).onNext(anyInt()); |
| 108 | + verify(w, never()).onCompleted(); |
| 109 | + verify(w, times(1)).onError(any(RuntimeException.class)); |
| 110 | + } |
| 111 | + |
76 | 112 | @Test
|
77 | 113 | public void testReduce() {
|
78 | 114 | Observable<Integer> observable = Observable.from(1, 2, 3, 4);
|
|
0 commit comments