Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/observable/ObservableFromSingleTest.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.observable;
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.observers.TestObserver;
23 import io.reactivex.rxjava3.operators.QueueFuseable;
24 import io.reactivex.rxjava3.subjects.SingleSubject;
25 import io.reactivex.rxjava3.testsupport.TestObserverEx;
26
27 public class ObservableFromSingleTest extends RxJavaTest {
28
29 @Test
30 public void success() {
31 Observable.fromSingle(Single.just(1).hide())
32 .test()
33 .assertResult(1);
34 }
35
36 @Test
37 public void error() {
38 Observable.fromSingle(Single.error(new TestException()).hide())
39 .test()
40 .assertFailure(TestException.class);
41 }
42
43 @Test
44 public void cancelComposes() {
45 SingleSubject<Integer> ms = SingleSubject.create();
46
47 TestObserver<Integer> to = Observable.fromSingle(ms)
48 .test();
49
50 to.assertEmpty();
51
52 assertTrue(ms.hasObservers());
53
54 to.dispose();
55
56 assertFalse(ms.hasObservers());
57 }
58
59 @Test
60 public void asyncFusion() {
61 TestObserverEx<Integer> to = new TestObserverEx<>();
62 to.setInitialFusionMode(QueueFuseable.ASYNC);
63
64 Observable.fromSingle(Single.just(1))
65 .subscribe(to);
66
67 to
68 .assertFuseable()
69 .assertFusionMode(QueueFuseable.ASYNC)
70 .assertResult(1);
71 }
72
73 @Test
74 public void syncFusionRejected() {
75 TestObserverEx<Integer> to = new TestObserverEx<>();
76 to.setInitialFusionMode(QueueFuseable.SYNC);
77
78 Observable.fromSingle(Single.just(1))
79 .subscribe(to);
80
81 to
82 .assertFuseable()
83 .assertFusionMode(QueueFuseable.NONE)
84 .assertResult(1);
85 }
86 }