Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/util/BlockingHelperTest.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.util;
15
16 import static org.junit.Assert.*;
17
18 import java.util.concurrent.*;
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 import io.reactivex.rxjava3.testsupport.TestHelper;
26
27 public class BlockingHelperTest extends RxJavaTest {
28
29 @Test
30 public void emptyEnum() {
31 TestHelper.checkUtilityClass(BlockingHelper.class);
32 }
33
34 @Test
35 public void interrupted() {
36 CountDownLatch cdl = new CountDownLatch(1);
37 Disposable d = Disposable.empty();
38
39 Thread.currentThread().interrupt();
40
41 try {
42 BlockingHelper.awaitForComplete(cdl, d);
43 } catch (IllegalStateException ex) {
44 // expected
45 }
46 assertTrue(d.isDisposed());
47 assertTrue(Thread.interrupted());
48 }
49
50 @Test
51 public void unblock() {
52 final CountDownLatch cdl = new CountDownLatch(1);
53 Disposable d = Disposable.empty();
54
55 Schedulers.computation().scheduleDirect(new Runnable() {
56 @Override
57 public void run() {
58 cdl.countDown();
59 }
60 }, 100, TimeUnit.MILLISECONDS);
61
62 BlockingHelper.awaitForComplete(cdl, d);
63
64 assertFalse(d.isDisposed());
65 }
66 }