Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableConcatWithMaybeTest.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.flowable;
15
16 import static org.junit.Assert.*;
17
18 import org.junit.Test;
19
20 import io.reactivex.rxjava3.core.*;
21 import io.reactivex.rxjava3.exceptions.TestException;
22 import io.reactivex.rxjava3.functions.Action;
23 import io.reactivex.rxjava3.subjects.MaybeSubject;
24 import io.reactivex.rxjava3.subscribers.TestSubscriber;
25
26 public class FlowableConcatWithMaybeTest extends RxJavaTest {
27
28 @Test
29 public void normalEmpty() {
30 final TestSubscriber<Integer> ts = new TestSubscriber<>();
31
32 Flowable.range(1, 5)
33 .concatWith(Maybe.<Integer>fromAction(new Action() {
34 @Override
35 public void run() throws Exception {
36 ts.onNext(100);
37 }
38 }))
39 .subscribe(ts);
40
41 ts.assertResult(1, 2, 3, 4, 5, 100);
42 }
43
44 @Test
45 public void normalNonEmpty() {
46 final TestSubscriber<Integer> ts = new TestSubscriber<>();
47
48 Flowable.range(1, 5)
49 .concatWith(Maybe.just(100))
50 .subscribe(ts);
51
52 ts.assertResult(1, 2, 3, 4, 5, 100);
53 }
54
55 @Test
56 public void backpressure() {
57 Flowable.range(1, 5)
58 .concatWith(Maybe.just(100))
59 .test(0)
60 .assertEmpty()
61 .requestMore(3)
62 .assertValues(1, 2, 3)
63 .requestMore(2)
64 .assertValues(1, 2, 3, 4, 5)
65 .requestMore(1)
66 .assertResult(1, 2, 3, 4, 5, 100);
67 }
68
69 @Test
70 public void mainError() {
71 final TestSubscriber<Integer> ts = new TestSubscriber<>();
72
73 Flowable.<Integer>error(new TestException())
74 .concatWith(Maybe.<Integer>fromAction(new Action() {
75 @Override
76 public void run() throws Exception {
77 ts.onNext(100);
78 }
79 }))
80 .subscribe(ts);
81
82 ts.assertFailure(TestException.class);
83 }
84
85 @Test
86 public void otherError() {
87 final TestSubscriber<Integer> ts = new TestSubscriber<>();
88
89 Flowable.range(1, 5)
90 .concatWith(Maybe.<Integer>error(new TestException()))
91 .subscribe(ts);
92
93 ts.assertFailure(TestException.class, 1, 2, 3, 4, 5);
94 }
95
96 @Test
97 public void takeMain() {
98 final TestSubscriber<Integer> ts = new TestSubscriber<>();
99
100 Flowable.range(1, 5)
101 .concatWith(Maybe.<Integer>fromAction(new Action() {
102 @Override
103 public void run() throws Exception {
104 ts.onNext(100);
105 }
106 }))
107 .take(3)
108 .subscribe(ts);
109
110 ts.assertResult(1, 2, 3);
111 }
112
113 @Test
114 public void cancelOther() {
115 MaybeSubject<Object> other = MaybeSubject.create();
116
117 TestSubscriber<Object> ts = Flowable.empty()
118 .concatWith(other)
119 .test();
120
121 assertTrue(other.hasObservers());
122
123 ts.cancel();
124
125 assertFalse(other.hasObservers());
126 }
127
128 }