Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/observers/DisposableLambdaObserverTest.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.observers;
15
16 import static org.junit.Assert.*;
17
18 import java.util.List;
19
20 import io.reactivex.rxjava3.disposables.Disposable;
21 import org.junit.Test;
22
23 import io.reactivex.rxjava3.core.RxJavaTest;
24 import io.reactivex.rxjava3.exceptions.TestException;
25 import io.reactivex.rxjava3.functions.Action;
26 import io.reactivex.rxjava3.internal.functions.Functions;
27 import io.reactivex.rxjava3.observers.TestObserver;
28 import io.reactivex.rxjava3.plugins.RxJavaPlugins;
29 import io.reactivex.rxjava3.testsupport.TestHelper;
30
31 public class DisposableLambdaObserverTest extends RxJavaTest {
32
33 @Test
34 public void doubleOnSubscribe() {
35 TestHelper.doubleOnSubscribe(new DisposableLambdaObserver<>(
36 new TestObserver<>(), Functions.emptyConsumer(), Functions.EMPTY_ACTION
37 ));
38 }
39
40 @Test
41 public void disposeCrash() {
42 List<Throwable> errors = TestHelper.trackPluginErrors();
43 try {
44 DisposableLambdaObserver<Integer> o = new DisposableLambdaObserver<>(
45 new TestObserver<>(), Functions.emptyConsumer(),
46 new Action() {
47 @Override
48 public void run() throws Exception {
49 throw new TestException();
50 }
51 }
52 );
53
54 o.onSubscribe(Disposable.empty());
55
56 assertFalse(o.isDisposed());
57
58 o.dispose();
59
60 assertTrue(o.isDisposed());
61
62 TestHelper.assertUndeliverable(errors, 0, TestException.class);
63 } finally {
64 RxJavaPlugins.reset();
65 }
66 }
67 }