Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableConcatWithSingleTest.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.subjects.SingleSubject;
23 import io.reactivex.rxjava3.subscribers.TestSubscriber;
24
25 public class FlowableConcatWithSingleTest extends RxJavaTest {
26
27 @Test
28 public void normal() {
29 final TestSubscriber<Integer> ts = new TestSubscriber<>();
30
31 Flowable.range(1, 5)
32 .concatWith(Single.just(100))
33 .subscribe(ts);
34
35 ts.assertResult(1, 2, 3, 4, 5, 100);
36 }
37
38 @Test
39 public void backpressure() {
40 Flowable.range(1, 5)
41 .concatWith(Single.just(100))
42 .test(0)
43 .assertEmpty()
44 .requestMore(3)
45 .assertValues(1, 2, 3)
46 .requestMore(2)
47 .assertValues(1, 2, 3, 4, 5)
48 .requestMore(1)
49 .assertResult(1, 2, 3, 4, 5, 100);
50 }
51
52 @Test
53 public void mainError() {
54 final TestSubscriber<Integer> ts = new TestSubscriber<>();
55
56 Flowable.<Integer>error(new TestException())
57 .concatWith(Single.just(100))
58 .subscribe(ts);
59
60 ts.assertFailure(TestException.class);
61 }
62
63 @Test
64 public void otherError() {
65 final TestSubscriber<Integer> ts = new TestSubscriber<>();
66
67 Flowable.range(1, 5)
68 .concatWith(Single.<Integer>error(new TestException()))
69 .subscribe(ts);
70
71 ts.assertFailure(TestException.class, 1, 2, 3, 4, 5);
72 }
73
74 @Test
75 public void takeMain() {
76 final TestSubscriber<Integer> ts = new TestSubscriber<>();
77
78 Flowable.range(1, 5)
79 .concatWith(Single.just(100))
80 .take(3)
81 .subscribe(ts);
82
83 ts.assertResult(1, 2, 3);
84 }
85
86 @Test
87 public void cancelOther() {
88 SingleSubject<Object> other = SingleSubject.create();
89
90 TestSubscriber<Object> ts = Flowable.empty()
91 .concatWith(other)
92 .test();
93
94 assertTrue(other.hasObservers());
95
96 ts.cancel();
97
98 assertFalse(other.hasObservers());
99 }
100
101 }