Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/single/SingleConcatMapCompletableTest.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 org.junit.Test;
19
20 import io.reactivex.rxjava3.core.*;
21 import io.reactivex.rxjava3.exceptions.TestException;
22 import io.reactivex.rxjava3.functions.*;
23 import io.reactivex.rxjava3.testsupport.TestHelper;
24
25 public class SingleConcatMapCompletableTest extends RxJavaTest {
26
27 @Test
28 public void dispose() {
29 TestHelper.checkDisposed(Single.just(1).concatMapCompletable(new Function<Integer, Completable>() {
30 @Override
31 public Completable apply(Integer v) throws Exception {
32 return Completable.complete();
33 }
34 }));
35 }
36
37 @Test
38 public void normal() {
39 final boolean[] b = { false };
40
41 Single.just(1)
42 .concatMapCompletable(new Function<Integer, Completable>() {
43 @Override
44 public Completable apply(Integer t) throws Exception {
45 return Completable.complete().doOnComplete(new Action() {
46 @Override
47 public void run() throws Exception {
48 b[0] = true;
49 }
50 });
51 }
52 })
53 .test()
54 .assertResult();
55
56 assertTrue(b[0]);
57 }
58
59 @Test
60 public void error() {
61 final boolean[] b = { false };
62
63 Single.<Integer>error(new TestException())
64 .concatMapCompletable(new Function<Integer, Completable>() {
65 @Override
66 public Completable apply(Integer t) throws Exception {
67 return Completable.complete().doOnComplete(new Action() {
68 @Override
69 public void run() throws Exception {
70 b[0] = true;
71 }
72 });
73 }
74 })
75 .test()
76 .assertFailure(TestException.class);
77
78 assertFalse(b[0]);
79 }
80
81 @Test
82 public void mapperThrows() {
83 final boolean[] b = { false };
84
85 Single.just(1)
86 .concatMapCompletable(new Function<Integer, Completable>() {
87 @Override
88 public Completable apply(Integer t) throws Exception {
89 throw new TestException();
90 }
91 })
92 .test()
93 .assertFailure(TestException.class);
94
95 assertFalse(b[0]);
96 }
97
98 @Test
99 public void mapperReturnsNull() {
100 final boolean[] b = { false };
101
102 Single.just(1)
103 .concatMapCompletable(new Function<Integer, Completable>() {
104 @Override
105 public Completable apply(Integer t) throws Exception {
106 return null;
107 }
108 })
109 .test()
110 .assertFailure(NullPointerException.class);
111
112 assertFalse(b[0]);
113 }
114 }