Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/NotificationLiteTest.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.flowable;
15
16 import static org.junit.Assert.*;
17
18 import io.reactivex.rxjava3.disposables.Disposable;
19 import org.junit.Test;
20
21 import io.reactivex.rxjava3.core.RxJavaTest;
22 import io.reactivex.rxjava3.exceptions.TestException;
23 import io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription;
24 import io.reactivex.rxjava3.internal.util.NotificationLite;
25 import io.reactivex.rxjava3.testsupport.TestHelper;
26
27 public class NotificationLiteTest extends RxJavaTest {
28
29 @Test
30 public void complete() {
31 Object n = NotificationLite.next("Hello");
32 Object c = NotificationLite.complete();
33
34 assertTrue(NotificationLite.isComplete(c));
35 assertFalse(NotificationLite.isComplete(n));
36
37 assertEquals("Hello", NotificationLite.getValue(n));
38 }
39
40 @Test
41 public void valueKind() {
42 assertSame(1, NotificationLite.next(1));
43 }
44
45 @Test
46 public void soloEnum() {
47 TestHelper.checkEnum(NotificationLite.class);
48 }
49
50 @Test
51 public void errorNotification() {
52 Object o = NotificationLite.error(new TestException());
53
54 assertEquals("NotificationLite.Error[io.reactivex.rxjava3.exceptions.TestException]", o.toString());
55
56 assertTrue(NotificationLite.isError(o));
57 assertFalse(NotificationLite.isComplete(o));
58 assertFalse(NotificationLite.isDisposable(o));
59 assertFalse(NotificationLite.isSubscription(o));
60
61 assertTrue(NotificationLite.getError(o) instanceof TestException);
62 }
63
64 @Test
65 public void completeNotification() {
66 Object o = NotificationLite.complete();
67 Object o2 = NotificationLite.complete();
68
69 assertSame(o, o2);
70
71 assertFalse(NotificationLite.isError(o));
72 assertTrue(NotificationLite.isComplete(o));
73 assertFalse(NotificationLite.isDisposable(o));
74 assertFalse(NotificationLite.isSubscription(o));
75
76 assertEquals("NotificationLite.Complete", o.toString());
77
78 assertTrue(NotificationLite.isComplete(o));
79 }
80
81 @Test
82 public void disposableNotification() {
83 Object o = NotificationLite.disposable(Disposable.empty());
84
85 assertEquals("NotificationLite.Disposable[RunnableDisposable(disposed=false, EmptyRunnable)]", o.toString());
86
87 assertFalse(NotificationLite.isError(o));
88 assertFalse(NotificationLite.isComplete(o));
89 assertTrue(NotificationLite.isDisposable(o));
90 assertFalse(NotificationLite.isSubscription(o));
91
92 assertNotNull(NotificationLite.getDisposable(o));
93 }
94
95 @Test
96 public void subscriptionNotification() {
97 Object o = NotificationLite.subscription(new BooleanSubscription());
98
99 assertEquals("NotificationLite.Subscription[BooleanSubscription(cancelled=false)]", o.toString());
100
101 assertFalse(NotificationLite.isError(o));
102 assertFalse(NotificationLite.isComplete(o));
103 assertFalse(NotificationLite.isDisposable(o));
104 assertTrue(NotificationLite.isSubscription(o));
105
106 assertNotNull(NotificationLite.getSubscription(o));
107 }
108
109 // TODO this test is no longer relevant as nulls are not allowed and value maps to itself
110 // @Test
111 // public void testValueKind() {
112 // assertTrue(NotificationLite.isNull(NotificationLite.next(null)));
113 // assertFalse(NotificationLite.isNull(NotificationLite.next(1)));
114 // assertFalse(NotificationLite.isNull(NotificationLite.error(new TestException())));
115 // assertFalse(NotificationLite.isNull(NotificationLite.completed()));
116 // assertFalse(NotificationLite.isNull(null));
117 //
118 // assertTrue(NotificationLite.isNext(NotificationLite.next(null)));
119 // assertTrue(NotificationLite.isNext(NotificationLite.next(1)));
120 // assertFalse(NotificationLite.isNext(NotificationLite.completed()));
121 // assertFalse(NotificationLite.isNext(null));
122 // assertFalse(NotificationLite.isNext(NotificationLite.error(new TestException())));
123 // }
124 }