Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeFlattenTest.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.maybe;
15
16 import org.junit.Test;
17
18 import io.reactivex.rxjava3.core.*;
19 import io.reactivex.rxjava3.exceptions.TestException;
20 import io.reactivex.rxjava3.functions.Function;
21 import io.reactivex.rxjava3.testsupport.TestHelper;
22
23 public class MaybeFlattenTest extends RxJavaTest {
24
25 @Test
26 public void dispose() {
27 TestHelper.checkDisposed(Maybe.just(1).flatMap(new Function<Integer, MaybeSource<Integer>>() {
28 @Override
29 public MaybeSource<Integer> apply(Integer v) throws Exception {
30 return Maybe.just(2);
31 }
32 }));
33 }
34
35 @Test
36 public void doubleOnSubscribe() {
37 TestHelper.checkDoubleOnSubscribeMaybe(new Function<Maybe<Integer>, MaybeSource<Integer>>() {
38 @Override
39 public MaybeSource<Integer> apply(Maybe<Integer> v) throws Exception {
40 return v.flatMap(new Function<Integer, MaybeSource<Integer>>() {
41 @Override
42 public MaybeSource<Integer> apply(Integer v) throws Exception {
43 return Maybe.just(2);
44 }
45 });
46 }
47 });
48 }
49
50 @Test
51 public void mainError() {
52 Maybe.<Integer>error(new TestException())
53 .flatMap(new Function<Integer, MaybeSource<Integer>>() {
54 @Override
55 public MaybeSource<Integer> apply(Integer v) throws Exception {
56 return Maybe.just(2);
57 }
58 })
59 .test()
60 .assertFailure(TestException.class);
61 }
62
63 @Test
64 public void mainEmpty() {
65 Maybe.<Integer>empty()
66 .flatMap(new Function<Integer, MaybeSource<Integer>>() {
67 @Override
68 public MaybeSource<Integer> apply(Integer v) throws Exception {
69 return Maybe.just(2);
70 }
71 })
72 .test()
73 .assertResult();
74 }
75
76 @Test
77 public void mapperThrows() {
78 Maybe.just(1)
79 .flatMap(new Function<Integer, MaybeSource<Integer>>() {
80 @Override
81 public MaybeSource<Integer> apply(Integer v) throws Exception {
82 throw new TestException();
83 }
84 })
85 .test()
86 .assertFailure(TestException.class);
87 }
88
89 @Test
90 public void mapperReturnsNull() {
91 Maybe.just(1)
92 .flatMap(new Function<Integer, MaybeSource<Integer>>() {
93 @Override
94 public MaybeSource<Integer> apply(Integer v) throws Exception {
95 return null;
96 }
97 })
98 .test()
99 .assertFailure(NullPointerException.class);
100 }
101 }