Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableOnErrorCompleteTest.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 java.io.IOException;
19
20 import org.junit.Test;
21
22 import io.reactivex.rxjava3.core.Flowable;
23 import io.reactivex.rxjava3.exceptions.*;
24 import io.reactivex.rxjava3.processors.PublishProcessor;
25 import io.reactivex.rxjava3.subscribers.TestSubscriber;
26 import io.reactivex.rxjava3.testsupport.*;
27
28 public class FlowableOnErrorCompleteTest {
29
30 @Test
31 public void normal() {
32 Flowable.range(1, 10)
33 .onErrorComplete()
34 .test()
35 .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
36 }
37
38 @Test
39 public void normalBackpressured() {
40 Flowable.range(1, 10)
41 .onErrorComplete()
42 .test(0)
43 .assertEmpty()
44 .requestMore(3)
45 .assertValuesOnly(1, 2, 3)
46 .requestMore(3)
47 .assertValuesOnly(1, 2, 3, 4, 5, 6)
48 .requestMore(4)
49 .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
50 }
51
52 @Test
53 public void empty() {
54 Flowable.empty()
55 .onErrorComplete()
56 .test()
57 .assertResult();
58 }
59
60 @Test
61 public void error() throws Throwable {
62 TestHelper.withErrorTracking(errors -> {
63 Flowable.error(new TestException())
64 .onErrorComplete()
65 .test()
66 .assertResult();
67
68 assertTrue("" + errors, errors.isEmpty());
69 });
70 }
71
72 @Test
73 public void errorMatches() throws Throwable {
74 TestHelper.withErrorTracking(errors -> {
75 Flowable.error(new TestException())
76 .onErrorComplete(error -> error instanceof TestException)
77 .test()
78 .assertResult();
79
80 assertTrue("" + errors, errors.isEmpty());
81 });
82 }
83
84 @Test
85 public void errorNotMatches() throws Throwable {
86 TestHelper.withErrorTracking(errors -> {
87 Flowable.error(new IOException())
88 .onErrorComplete(error -> error instanceof TestException)
89 .test()
90 .assertFailure(IOException.class);
91
92 assertTrue("" + errors, errors.isEmpty());
93 });
94 }
95
96 @Test
97 public void errorPredicateCrash() throws Throwable {
98 TestHelper.withErrorTracking(errors -> {
99 TestSubscriberEx<Object> ts = Flowable.error(new IOException())
100 .onErrorComplete(error -> { throw new TestException(); })
101 .subscribeWith(new TestSubscriberEx<>())
102 .assertFailure(CompositeException.class);
103
104 TestHelper.assertError(ts, 0, IOException.class);
105 TestHelper.assertError(ts, 1, TestException.class);
106
107 assertTrue("" + errors, errors.isEmpty());
108 });
109 }
110
111 @Test
112 public void itemsThenError() throws Throwable {
113 TestHelper.withErrorTracking(errors -> {
114 Flowable.range(1, 5)
115 .map(v -> 4 / (3 - v))
116 .onErrorComplete()
117 .test()
118 .assertResult(2, 4);
119
120 assertTrue("" + errors, errors.isEmpty());
121 });
122 }
123
124 @Test
125 public void cancel() {
126 PublishProcessor<Integer> pp = PublishProcessor.create();
127
128 TestSubscriber<Integer> ts = pp
129 .onErrorComplete()
130 .test();
131
132 assertTrue("No subscribers?!", pp.hasSubscribers());
133
134 ts.cancel();
135
136 assertFalse("Still subscribers?!", pp.hasSubscribers());
137 }
138
139 @Test
140 public void onSubscribe() {
141 TestHelper.checkDoubleOnSubscribeFlowable(f -> f.onErrorComplete());
142 }
143 }