Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/mixed/CompletableAndThenPublisherTest.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.mixed;
15
16 import static org.junit.Assert.*;
17
18 import org.junit.Test;
19 import org.reactivestreams.Publisher;
20
21 import io.reactivex.rxjava3.core.*;
22 import io.reactivex.rxjava3.functions.Function;
23 import io.reactivex.rxjava3.processors.PublishProcessor;
24 import io.reactivex.rxjava3.subjects.CompletableSubject;
25 import io.reactivex.rxjava3.subscribers.TestSubscriber;
26 import io.reactivex.rxjava3.testsupport.TestHelper;
27
28 public class CompletableAndThenPublisherTest extends RxJavaTest {
29
30 @Test
31 public void cancelMain() {
32 CompletableSubject cs = CompletableSubject.create();
33 PublishProcessor<Integer> pp = PublishProcessor.create();
34
35 TestSubscriber<Integer> ts = cs.andThen(pp)
36 .test();
37
38 assertTrue(cs.hasObservers());
39 assertFalse(pp.hasSubscribers());
40
41 ts.cancel();
42
43 assertFalse(cs.hasObservers());
44 assertFalse(pp.hasSubscribers());
45 }
46
47 @Test
48 public void cancelOther() {
49 CompletableSubject cs = CompletableSubject.create();
50 PublishProcessor<Integer> pp = PublishProcessor.create();
51
52 TestSubscriber<Integer> ts = cs.andThen(pp)
53 .test();
54
55 assertTrue(cs.hasObservers());
56 assertFalse(pp.hasSubscribers());
57
58 cs.onComplete();
59
60 assertFalse(cs.hasObservers());
61 assertTrue(pp.hasSubscribers());
62
63 ts.cancel();
64
65 assertFalse(cs.hasObservers());
66 assertFalse(pp.hasSubscribers());
67 }
68
69 @Test
70 public void doubleOnSubscribe() {
71 TestHelper.checkDoubleOnSubscribeCompletableToFlowable(new Function<Completable, Publisher<Object>>() {
72 @Override
73 public Publisher<Object> apply(Completable m) throws Exception {
74 return m.andThen(Flowable.never());
75 }
76 });
77 }
78 }