Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/observers/BlockingMultiObserverTest.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.concurrent.TimeUnit;
19
20 import org.junit.Test;
21
22 import io.reactivex.rxjava3.core.RxJavaTest;
23 import io.reactivex.rxjava3.disposables.*;
24 import io.reactivex.rxjava3.schedulers.Schedulers;
25
26 public class BlockingMultiObserverTest extends RxJavaTest {
27
28 @Test
29 public void dispose() {
30 BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<>();
31 bmo.dispose();
32
33 Disposable d = Disposable.empty();
34
35 bmo.onSubscribe(d);
36 }
37
38 @Test
39 public void blockingGetDefault() {
40 final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<>();
41
42 Schedulers.single().scheduleDirect(new Runnable() {
43 @Override
44 public void run() {
45 bmo.onSuccess(1);
46 }
47 }, 100, TimeUnit.MILLISECONDS);
48
49 assertEquals(1, bmo.blockingGet(0).intValue());
50 }
51
52 @Test
53 public void blockingAwait() {
54 final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<>();
55
56 Schedulers.single().scheduleDirect(new Runnable() {
57 @Override
58 public void run() {
59 bmo.onSuccess(1);
60 }
61 }, 100, TimeUnit.MILLISECONDS);
62
63 assertTrue(bmo.blockingAwait(1, TimeUnit.MINUTES));
64 }
65
66 @Test
67 public void blockingGetDefaultInterrupt() {
68 final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<>();
69
70 Thread.currentThread().interrupt();
71 try {
72 bmo.blockingGet(0);
73 fail("Should have thrown");
74 } catch (RuntimeException ex) {
75 assertTrue(ex.getCause() instanceof InterruptedException);
76 } finally {
77 Thread.interrupted();
78 }
79 }
80 }