Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/single/SingleFlatMapNotificationTest.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.assertTrue;
17
18 import java.io.IOException;
19 import java.util.List;
20
21 import org.junit.Test;
22
23 import io.reactivex.rxjava3.core.*;
24 import io.reactivex.rxjava3.exceptions.*;
25 import io.reactivex.rxjava3.functions.Function;
26 import io.reactivex.rxjava3.internal.functions.Functions;
27 import io.reactivex.rxjava3.testsupport.*;
28
29 public class SingleFlatMapNotificationTest extends RxJavaTest {
30
31 @Test
32 public void dispose() {
33 TestHelper.checkDisposed(Single.just(1)
34 .flatMap(Functions.justFunction(Single.just(1)),
35 Functions.justFunction(Single.just(1))));
36 }
37
38 @Test
39 public void doubleOnSubscribe() {
40 TestHelper.checkDoubleOnSubscribeSingle(new Function<Single<Integer>, SingleSource<Integer>>() {
41 @Override
42 public SingleSource<Integer> apply(Single<Integer> m) throws Exception {
43 return m
44 .flatMap(Functions.justFunction(Single.just(1)),
45 Functions.justFunction(Single.just(1)));
46 }
47 });
48 }
49
50 @Test
51 public void onSuccessNull() {
52 Single.just(1)
53 .flatMap(Functions.justFunction((Single<Integer>)null),
54 Functions.justFunction(Single.just(1)))
55 .test()
56 .assertFailure(NullPointerException.class);
57 }
58
59 @Test
60 public void onErrorNull() {
61 TestObserverEx<Integer> to = Single.<Integer>error(new TestException())
62 .flatMap(Functions.justFunction(Single.just(1)),
63 Functions.justFunction((Single<Integer>)null))
64 .to(TestHelper.<Integer>testConsumer())
65 .assertFailure(CompositeException.class);
66
67 List<Throwable> ce = TestHelper.compositeList(to.errors().get(0));
68
69 TestHelper.assertError(ce, 0, TestException.class);
70 TestHelper.assertError(ce, 1, NullPointerException.class);
71 }
72
73 @Test
74 public void onSuccessError() {
75 Single.just(1)
76 .flatMap(Functions.justFunction(Single.<Integer>error(new TestException())),
77 Functions.justFunction((Single<Integer>)null))
78 .test()
79 .assertFailure(TestException.class);
80 }
81
82 @Test
83 public void onSucccessSuccess() {
84 Single.just(1)
85 .flatMap(v -> Single.just(2), e -> Single.just(3))
86 .test()
87 .assertResult(2);
88 }
89
90 @Test
91 public void onErrorSuccess() throws Throwable {
92 TestHelper.withErrorTracking(errors -> {
93 Single.error(new TestException())
94 .flatMap(v -> Single.just(2), e -> Single.just(3))
95 .test()
96 .assertResult(3);
97
98 assertTrue("" + errors, errors.isEmpty());
99 });
100 }
101
102 @Test
103 public void onErrorError() throws Throwable {
104 TestHelper.withErrorTracking(errors -> {
105 Single.error(new TestException())
106 .flatMap(v -> Single.just(2), e -> Single.<Integer>error(new IOException()))
107 .test()
108 .assertFailure(IOException.class);
109
110 assertTrue("" + errors, errors.isEmpty());
111 });
112 }
113 }