Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/single/SingleOnErrorCompleteTest.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.single;
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.Single;
23 import io.reactivex.rxjava3.exceptions.*;
24 import io.reactivex.rxjava3.observers.TestObserver;
25 import io.reactivex.rxjava3.subjects.*;
26 import io.reactivex.rxjava3.testsupport.*;
27
28 public class SingleOnErrorCompleteTest {
29
30 @Test
31 public void normal() {
32 Single.just(1)
33 .onErrorComplete()
34 .test()
35 .assertResult(1);
36 }
37
38 @Test
39 public void error() throws Throwable {
40 TestHelper.withErrorTracking(errors -> {
41 Single.error(new TestException())
42 .onErrorComplete()
43 .test()
44 .assertResult();
45
46 assertTrue("" + errors, errors.isEmpty());
47 });
48 }
49
50 @Test
51 public void errorMatches() throws Throwable {
52 TestHelper.withErrorTracking(errors -> {
53 Single.error(new TestException())
54 .onErrorComplete(error -> error instanceof TestException)
55 .test()
56 .assertResult();
57
58 assertTrue("" + errors, errors.isEmpty());
59 });
60 }
61
62 @Test
63 public void errorNotMatches() throws Throwable {
64 TestHelper.withErrorTracking(errors -> {
65 Single.error(new IOException())
66 .onErrorComplete(error -> error instanceof TestException)
67 .test()
68 .assertFailure(IOException.class);
69
70 assertTrue("" + errors, errors.isEmpty());
71 });
72 }
73
74 @Test
75 public void errorPredicateCrash() throws Throwable {
76 TestHelper.withErrorTracking(errors -> {
77 TestObserverEx<Object> to = Single.error(new IOException())
78 .onErrorComplete(error -> { throw new TestException(); })
79 .subscribeWith(new TestObserverEx<>())
80 .assertFailure(CompositeException.class);
81
82 TestHelper.assertError(to, 0, IOException.class);
83 TestHelper.assertError(to, 1, TestException.class);
84
85 assertTrue("" + errors, errors.isEmpty());
86 });
87 }
88
89 @Test
90 public void dispose() {
91 SingleSubject<Integer> ss = SingleSubject.create();
92
93 TestObserver<Integer> to = ss
94 .onErrorComplete()
95 .test();
96
97 assertTrue("No subscribers?!", ss.hasObservers());
98
99 to.dispose();
100
101 assertFalse("Still subscribers?!", ss.hasObservers());
102 }
103
104 @Test
105 public void onSubscribe() {
106 TestHelper.checkDoubleOnSubscribeSingleToMaybe(f -> f.onErrorComplete());
107 }
108
109 @Test
110 public void isDisposed() {
111 TestHelper.checkDisposed(SingleSubject.create().onErrorComplete());
112 }
113 }