Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/subscribers/BasicFuseableConditionalSubscriberTest.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.subscribers;
15
16 import static org.junit.Assert.*;
17 import static org.mockito.ArgumentMatchers.any;
18 import static org.mockito.Mockito.*;
19
20 import org.junit.Test;
21 import org.reactivestreams.Subscription;
22
23 import io.reactivex.rxjava3.annotations.*;
24 import io.reactivex.rxjava3.core.*;
25 import io.reactivex.rxjava3.internal.subscriptions.*;
26 import io.reactivex.rxjava3.operators.ConditionalSubscriber;
27 import io.reactivex.rxjava3.operators.QueueFuseable;
28 import io.reactivex.rxjava3.testsupport.*;
29
30 public class BasicFuseableConditionalSubscriberTest extends RxJavaTest {
31
32 @Test
33 public void offerThrows() {
34 ConditionalSubscriber<Integer> cs = new ConditionalSubscriber<Integer>() {
35
36 @Override
37 public void onSubscribe(Subscription s) {
38 }
39
40 @Override
41 public void onNext(Integer t) {
42 }
43
44 @Override
45 public void onError(Throwable t) {
46 }
47
48 @Override
49 public void onComplete() {
50 }
51
52 @Override
53 public boolean tryOnNext(Integer t) {
54 return false;
55 }
56 };
57
58 BasicFuseableConditionalSubscriber<Integer, Integer> fcs = new BasicFuseableConditionalSubscriber<Integer, Integer>(cs) {
59
60 @Override
61 public boolean tryOnNext(Integer t) {
62 return false;
63 }
64
65 @Override
66 public void onNext(Integer t) {
67 }
68
69 @Override
70 public int requestFusion(int mode) {
71 return 0;
72 }
73
74 @Nullable
75 @Override
76 public Integer poll() throws Exception {
77 return null;
78 }
79 };
80
81 fcs.onSubscribe(new ScalarSubscription<>(fcs, 1));
82
83 TestHelper.assertNoOffer(fcs);
84
85 assertFalse(fcs.isEmpty());
86 fcs.clear();
87 assertTrue(fcs.isEmpty());
88 }
89
90 @Test
91 public void implementationStopsOnSubscribe() {
92 @SuppressWarnings("unchecked")
93 ConditionalSubscriber<Integer> ts = mock(ConditionalSubscriber.class);
94
95 BasicFuseableConditionalSubscriber<Integer, Integer> bfs = new BasicFuseableConditionalSubscriber<Integer, Integer>(ts) {
96
97 @Override
98 protected boolean beforeDownstream() {
99 return false;
100 }
101
102 @Override
103 public void onNext(@NonNull Integer t) {
104 ts.onNext(t);
105 }
106
107 @Override
108 public int requestFusion(int mode) {
109 // TODO Auto-generated method stub
110 return 0;
111 }
112
113 @Override
114 public boolean tryOnNext(@NonNull Integer t) {
115 // TODO Auto-generated method stub
116 return false;
117 }
118
119 @Override
120 public @Nullable Integer poll() throws Throwable {
121 return null;
122 }
123 };
124
125 bfs.onSubscribe(new BooleanSubscription());
126
127 verify(ts, never()).onSubscribe(any());
128 }
129
130 @Test
131 public void doubleOnSubscribe() {
132 TestHelper.checkDoubleOnSubscribeFlowable(f -> f
133 .map(v -> v)
134 .filter(v -> true)
135 );
136 }
137
138 @Test
139 public void transitiveBoundaryFusionNone() {
140 @SuppressWarnings("unchecked")
141 ConditionalSubscriber<Integer> ts = mock(ConditionalSubscriber.class);
142
143 BasicFuseableConditionalSubscriber<Integer, Integer> bfs = new BasicFuseableConditionalSubscriber<Integer, Integer>(ts) {
144
145 @Override
146 protected boolean beforeDownstream() {
147 return false;
148 }
149
150 @Override
151 public void onNext(@NonNull Integer t) {
152 ts.onNext(t);
153 }
154
155 @Override
156 public int requestFusion(int mode) {
157 // TODO Auto-generated method stub
158 return 0;
159 }
160
161 @Override
162 public boolean tryOnNext(@NonNull Integer t) {
163 // TODO Auto-generated method stub
164 return false;
165 }
166
167 @Override
168 public @Nullable Integer poll() throws Throwable {
169 return null;
170 }
171 };
172
173 bfs.onSubscribe(new BooleanSubscription());
174
175 assertEquals(QueueFuseable.NONE, bfs.transitiveBoundaryFusion(QueueFuseable.ANY));
176 }
177
178 @Test
179 public void transitiveBoundaryFusionAsync() {
180 @SuppressWarnings("unchecked")
181 ConditionalSubscriber<Integer> ts = mock(ConditionalSubscriber.class);
182
183 BasicFuseableConditionalSubscriber<Integer, Integer> bfs = new BasicFuseableConditionalSubscriber<Integer, Integer>(ts) {
184
185 @Override
186 protected boolean beforeDownstream() {
187 return false;
188 }
189
190 @Override
191 public void onNext(@NonNull Integer t) {
192 ts.onNext(t);
193 }
194
195 @Override
196 public int requestFusion(int mode) {
197 // TODO Auto-generated method stub
198 return 0;
199 }
200
201 @Override
202 public boolean tryOnNext(@NonNull Integer t) {
203 // TODO Auto-generated method stub
204 return false;
205 }
206
207 @Override
208 public @Nullable Integer poll() throws Throwable {
209 return null;
210 }
211 };
212
213 bfs.onSubscribe(EmptySubscription.INSTANCE);
214
215 assertEquals(QueueFuseable.ASYNC, bfs.transitiveBoundaryFusion(QueueFuseable.ANY));
216 }
217
218 @Test
219 public void transitiveBoundaryFusionAsyncBoundary() {
220 @SuppressWarnings("unchecked")
221 ConditionalSubscriber<Integer> ts = mock(ConditionalSubscriber.class);
222
223 BasicFuseableConditionalSubscriber<Integer, Integer> bfs = new BasicFuseableConditionalSubscriber<Integer, Integer>(ts) {
224
225 @Override
226 protected boolean beforeDownstream() {
227 return false;
228 }
229
230 @Override
231 public void onNext(@NonNull Integer t) {
232 ts.onNext(t);
233 }
234
235 @Override
236 public int requestFusion(int mode) {
237 // TODO Auto-generated method stub
238 return 0;
239 }
240
241 @Override
242 public boolean tryOnNext(@NonNull Integer t) {
243 // TODO Auto-generated method stub
244 return false;
245 }
246
247 @Override
248 public @Nullable Integer poll() throws Throwable {
249 return null;
250 }
251 };
252
253 bfs.onSubscribe(EmptySubscription.INSTANCE);
254
255 assertEquals(QueueFuseable.NONE, bfs.transitiveBoundaryFusion(QueueFuseable.ANY | QueueFuseable.BOUNDARY));
256 }
257 }