Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/single/SingleDematerializeTest.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 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.internal.functions.Functions;
22 import io.reactivex.rxjava3.subjects.SingleSubject;
23 import io.reactivex.rxjava3.testsupport.TestHelper;
24
25 public class SingleDematerializeTest extends RxJavaTest {
26
27 @Test
28 public void success() {
29 Single.just(Notification.createOnNext(1))
30 .dematerialize(Functions.<Notification<Integer>>identity())
31 .test()
32 .assertResult(1);
33 }
34
35 @Test
36 public void empty() {
37 Single.just(Notification.<Integer>createOnComplete())
38 .dematerialize(Functions.<Notification<Integer>>identity())
39 .test()
40 .assertResult();
41 }
42
43 @Test
44 public void error() {
45 Single.<Notification<Integer>>error(new TestException())
46 .dematerialize(Functions.<Notification<Integer>>identity())
47 .test()
48 .assertFailure(TestException.class);
49 }
50
51 @Test
52 public void errorNotification() {
53 Single.just(Notification.<Integer>createOnError(new TestException()))
54 .dematerialize(Functions.<Notification<Integer>>identity())
55 .test()
56 .assertFailure(TestException.class);
57 }
58
59 @Test
60 public void doubleOnSubscribe() {
61 TestHelper.checkDoubleOnSubscribeSingleToMaybe(new Function<Single<Object>, MaybeSource<Object>>() {
62 @SuppressWarnings({ "unchecked", "rawtypes" })
63 @Override
64 public MaybeSource<Object> apply(Single<Object> v) throws Exception {
65 return v.dematerialize((Function)Functions.identity());
66 }
67 });
68 }
69
70 @Test
71 public void dispose() {
72 TestHelper.checkDisposed(SingleSubject.<Notification<Integer>>create().dematerialize(Functions.<Notification<Integer>>identity()));
73 }
74
75 @Test
76 public void selectorCrash() {
77 Single.just(Notification.createOnNext(1))
78 .dematerialize(new Function<Notification<Integer>, Notification<Integer>>() {
79 @Override
80 public Notification<Integer> apply(Notification<Integer> v) throws Exception {
81 throw new TestException();
82 }
83 })
84 .test()
85 .assertFailure(TestException.class);
86 }
87
88 @Test
89 public void selectorNull() {
90 Single.just(Notification.createOnNext(1))
91 .dematerialize(Functions.justFunction((Notification<Integer>)null))
92 .test()
93 .assertFailure(NullPointerException.class);
94 }
95
96 @Test
97 public void selectorDifferentType() {
98 Single.just(Notification.createOnNext(1))
99 .dematerialize(new Function<Notification<Integer>, Notification<String>>() {
100 @Override
101 public Notification<String> apply(Notification<Integer> v) throws Exception {
102 return Notification.createOnNext("Value-" + 1);
103 }
104 })
105 .test()
106 .assertResult("Value-1");
107 }
108 }