Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableFromSingleTest.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 org.junit.Test;
19
20 import io.reactivex.rxjava3.core.*;
21 import io.reactivex.rxjava3.exceptions.TestException;
22 import io.reactivex.rxjava3.operators.QueueFuseable;
23 import io.reactivex.rxjava3.subjects.SingleSubject;
24 import io.reactivex.rxjava3.subscribers.TestSubscriber;
25 import io.reactivex.rxjava3.testsupport.TestSubscriberEx;
26
27 public class FlowableFromSingleTest extends RxJavaTest {
28
29 @Test
30 public void success() {
31 Flowable.fromSingle(Single.just(1).hide())
32 .test()
33 .assertResult(1);
34 }
35
36 @Test
37 public void error() {
38 Flowable.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 TestSubscriber<Integer> ts = Flowable.fromSingle(ms)
48 .test();
49
50 ts.assertEmpty();
51
52 assertTrue(ms.hasObservers());
53
54 ts.cancel();
55
56 assertFalse(ms.hasObservers());
57 }
58
59 @Test
60 public void asyncFusion() {
61 TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
62 ts.setInitialFusionMode(QueueFuseable.ASYNC);
63
64 Flowable.fromSingle(Single.just(1))
65 .subscribe(ts);
66
67 ts
68 .assertFuseable()
69 .assertFusionMode(QueueFuseable.ASYNC)
70 .assertResult(1);
71 }
72
73 @Test
74 public void syncFusionRejected() {
75 TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
76 ts.setInitialFusionMode(QueueFuseable.SYNC);
77
78 Flowable.fromSingle(Single.just(1))
79 .subscribe(ts);
80
81 ts
82 .assertFuseable()
83 .assertFusionMode(QueueFuseable.NONE)
84 .assertResult(1);
85 }
86 }