Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeIsEmptyTest.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 static org.junit.Assert.assertTrue;
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.Function;
23 import io.reactivex.rxjava3.processors.PublishProcessor;
24 import io.reactivex.rxjava3.testsupport.TestHelper;
25
26 public class MaybeIsEmptyTest extends RxJavaTest {
27
28 @Test
29 public void normal() {
30 Maybe.just(1)
31 .isEmpty()
32 .test()
33 .assertResult(false);
34 }
35
36 @Test
37 public void empty() {
38 Maybe.empty()
39 .isEmpty()
40 .test()
41 .assertResult(true);
42 }
43
44 @Test
45 public void error() {
46 Maybe.error(new TestException())
47 .isEmpty()
48 .test()
49 .assertFailure(TestException.class);
50 }
51
52 @Test
53 public void fusedBackToMaybe() {
54 assertTrue(Maybe.just(1)
55 .isEmpty()
56 .toMaybe() instanceof MaybeIsEmpty);
57 }
58
59 @Test
60 public void normalToMaybe() {
61 Maybe.just(1)
62 .isEmpty()
63 .toMaybe()
64 .test()
65 .assertResult(false);
66 }
67
68 @Test
69 public void emptyToMaybe() {
70 Maybe.empty()
71 .isEmpty()
72 .toMaybe()
73 .test()
74 .assertResult(true);
75 }
76
77 @Test
78 public void errorToMaybe() {
79 Maybe.error(new TestException())
80 .isEmpty()
81 .toMaybe()
82 .test()
83 .assertFailure(TestException.class);
84 }
85
86 @Test
87 public void dispose() {
88 TestHelper.checkDisposedMaybeToSingle(new Function<Maybe<Object>, SingleSource<Boolean>>() {
89 @Override
90 public SingleSource<Boolean> apply(Maybe<Object> m) throws Exception {
91 return m.isEmpty();
92 }
93 });
94 }
95
96 @Test
97 public void isDisposed() {
98 PublishProcessor<Integer> pp = PublishProcessor.create();
99
100 TestHelper.checkDisposed(pp.singleElement().isEmpty());
101 }
102
103 @Test
104 public void doubleOnSubscribe() {
105 TestHelper.checkDoubleOnSubscribeMaybeToSingle(new Function<Maybe<Object>, Single<Boolean>>() {
106 @Override
107 public Single<Boolean> apply(Maybe<Object> f) throws Exception {
108 return f.isEmpty();
109 }
110 });
111 }
112
113 @Test
114 public void disposeToMaybe() {
115 TestHelper.checkDisposedMaybe(new Function<Maybe<Object>, Maybe<Boolean>>() {
116 @Override
117 public Maybe<Boolean> apply(Maybe<Object> m) throws Exception {
118 return m.isEmpty().toMaybe();
119 }
120 });
121 }
122
123 @Test
124 public void isDisposedToMaybe() {
125 PublishProcessor<Integer> pp = PublishProcessor.create();
126
127 TestHelper.checkDisposed(pp.singleElement().isEmpty().toMaybe());
128 }
129
130 @Test
131 public void doubleOnSubscribeToMaybe() {
132 TestHelper.checkDoubleOnSubscribeMaybe(new Function<Maybe<Object>, Maybe<Boolean>>() {
133 @Override
134 public Maybe<Boolean> apply(Maybe<Object> f) throws Exception {
135 return f.isEmpty().toMaybe();
136 }
137 });
138 }
139 }