Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/observable/ObservableSkipUntilTest.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.operators.observable;
15
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.*;
18
19 import org.junit.*;
20
21 import io.reactivex.rxjava3.core.*;
22 import io.reactivex.rxjava3.functions.Function;
23 import io.reactivex.rxjava3.subjects.PublishSubject;
24 import io.reactivex.rxjava3.testsupport.TestHelper;
25
26 public class ObservableSkipUntilTest extends RxJavaTest {
27 Observer<Object> observer;
28
29 @Before
30 public void before() {
31 observer = TestHelper.mockObserver();
32 }
33
34 @Test
35 public void normal1() {
36 PublishSubject<Integer> source = PublishSubject.create();
37 PublishSubject<Integer> other = PublishSubject.create();
38
39 Observable<Integer> m = source.skipUntil(other);
40 m.subscribe(observer);
41
42 source.onNext(0);
43 source.onNext(1);
44
45 other.onNext(100);
46
47 source.onNext(2);
48 source.onNext(3);
49 source.onNext(4);
50 source.onComplete();
51
52 verify(observer, never()).onError(any(Throwable.class));
53 verify(observer, times(1)).onNext(2);
54 verify(observer, times(1)).onNext(3);
55 verify(observer, times(1)).onNext(4);
56 verify(observer, times(1)).onComplete();
57 }
58
59 @Test
60 public void otherNeverFires() {
61 PublishSubject<Integer> source = PublishSubject.create();
62
63 Observable<Integer> m = source.skipUntil(Observable.never());
64
65 m.subscribe(observer);
66
67 source.onNext(0);
68 source.onNext(1);
69 source.onNext(2);
70 source.onNext(3);
71 source.onNext(4);
72 source.onComplete();
73
74 verify(observer, never()).onError(any(Throwable.class));
75 verify(observer, never()).onNext(any());
76 verify(observer, times(1)).onComplete();
77 }
78
79 @Test
80 public void otherEmpty() {
81 PublishSubject<Integer> source = PublishSubject.create();
82
83 Observable<Integer> m = source.skipUntil(Observable.empty());
84
85 m.subscribe(observer);
86
87 verify(observer, never()).onError(any(Throwable.class));
88 verify(observer, never()).onNext(any());
89 verify(observer, never()).onComplete();
90 }
91
92 @Test
93 public void otherFiresAndCompletes() {
94 PublishSubject<Integer> source = PublishSubject.create();
95 PublishSubject<Integer> other = PublishSubject.create();
96
97 Observable<Integer> m = source.skipUntil(other);
98 m.subscribe(observer);
99
100 source.onNext(0);
101 source.onNext(1);
102
103 other.onNext(100);
104 other.onComplete();
105
106 source.onNext(2);
107 source.onNext(3);
108 source.onNext(4);
109 source.onComplete();
110
111 verify(observer, never()).onError(any(Throwable.class));
112 verify(observer, times(1)).onNext(2);
113 verify(observer, times(1)).onNext(3);
114 verify(observer, times(1)).onNext(4);
115 verify(observer, times(1)).onComplete();
116 }
117
118 @Test
119 public void sourceThrows() {
120 PublishSubject<Integer> source = PublishSubject.create();
121 PublishSubject<Integer> other = PublishSubject.create();
122
123 Observable<Integer> m = source.skipUntil(other);
124 m.subscribe(observer);
125
126 source.onNext(0);
127 source.onNext(1);
128
129 other.onNext(100);
130 other.onComplete();
131
132 source.onNext(2);
133 source.onError(new RuntimeException("Forced failure"));
134
135 verify(observer, times(1)).onNext(2);
136 verify(observer, times(1)).onError(any(Throwable.class));
137 verify(observer, never()).onComplete();
138 }
139
140 @Test
141 public void otherThrowsImmediately() {
142 PublishSubject<Integer> source = PublishSubject.create();
143 PublishSubject<Integer> other = PublishSubject.create();
144
145 Observable<Integer> m = source.skipUntil(other);
146 m.subscribe(observer);
147
148 source.onNext(0);
149 source.onNext(1);
150
151 other.onError(new RuntimeException("Forced failure"));
152
153 verify(observer, never()).onNext(any());
154 verify(observer, times(1)).onError(any(Throwable.class));
155 verify(observer, never()).onComplete();
156 }
157
158 @Test
159 public void dispose() {
160 TestHelper.checkDisposed(PublishSubject.create().skipUntil(PublishSubject.create()));
161 }
162
163 @Test
164 public void doubleOnSubscribe() {
165 TestHelper.checkDoubleOnSubscribeObservable(new Function<Observable<Object>, ObservableSource<Object>>() {
166 @Override
167 public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
168 return o.skipUntil(Observable.never());
169 }
170 });
171
172 TestHelper.checkDoubleOnSubscribeObservable(new Function<Observable<Object>, ObservableSource<Object>>() {
173 @Override
174 public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
175 return Observable.never().skipUntil(o);
176 }
177 });
178 }
179 }