Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableHideTest.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.assertFalse;
17 import static org.mockito.ArgumentMatchers.any;
18 import static org.mockito.Mockito.*;
19
20 import org.junit.Test;
21 import org.reactivestreams.Subscriber;
22
23 import io.reactivex.rxjava3.core.*;
24 import io.reactivex.rxjava3.exceptions.TestException;
25 import io.reactivex.rxjava3.functions.Function;
26 import io.reactivex.rxjava3.processors.PublishProcessor;
27 import io.reactivex.rxjava3.testsupport.TestHelper;
28
29 public class FlowableHideTest extends RxJavaTest {
30 @Test
31 public void hiding() {
32 PublishProcessor<Integer> src = PublishProcessor.create();
33
34 Flowable<Integer> dst = src.hide();
35
36 assertFalse(dst instanceof PublishProcessor);
37
38 Subscriber<Object> subscriber = TestHelper.mockSubscriber();
39
40 dst.subscribe(subscriber);
41
42 src.onNext(1);
43 src.onComplete();
44
45 verify(subscriber).onNext(1);
46 verify(subscriber).onComplete();
47 verify(subscriber, never()).onError(any(Throwable.class));
48 }
49
50 @Test
51 public void hidingError() {
52 PublishProcessor<Integer> src = PublishProcessor.create();
53
54 Flowable<Integer> dst = src.hide();
55
56 assertFalse(dst instanceof PublishProcessor);
57
58 Subscriber<Object> subscriber = TestHelper.mockSubscriber();
59
60 dst.subscribe(subscriber);
61
62 src.onError(new TestException());
63
64 verify(subscriber, never()).onNext(any());
65 verify(subscriber, never()).onComplete();
66 verify(subscriber).onError(any(TestException.class));
67 }
68
69 @Test
70 public void doubleOnSubscribe() {
71 TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Flowable<Object>>() {
72 @Override
73 public Flowable<Object> apply(Flowable<Object> f)
74 throws Exception {
75 return f.hide();
76 }
77 });
78 }
79
80 @Test
81 public void disposed() {
82 TestHelper.checkDisposed(PublishProcessor.create().hide());
83 }
84 }