Debian Codegraph @

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