Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/completable/CompletableToFutureTest.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.completable;
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.*;
23 import io.reactivex.rxjava3.exceptions.TestException;
24 import io.reactivex.rxjava3.schedulers.Schedulers;
25 import io.reactivex.rxjava3.subjects.CompletableSubject;
26
27 public class CompletableToFutureTest extends RxJavaTest {
28
29 @Test
30 public void empty() throws Exception {
31 assertNull(Completable.complete()
32 .subscribeOn(Schedulers.computation())
33 .toFuture()
34 .get());
35 }
36
37 @Test
38 public void error() throws InterruptedException {
39 try {
40 Completable.error(new TestException())
41 .subscribeOn(Schedulers.computation())
42 .toFuture()
43 .get();
44
45 fail("Should have thrown!");
46 } catch (ExecutionException ex) {
47 assertTrue("" + ex.getCause(), ex.getCause() instanceof TestException);
48 }
49 }
50
51 @Test
52 public void cancel() {
53 CompletableSubject cs = CompletableSubject.create();
54
55 Future<Void> f = cs.toFuture();
56
57 assertTrue(cs.hasObservers());
58
59 f.cancel(true);
60
61 assertFalse(cs.hasObservers());
62 }
63
64 @Test
65 public void cancel2() {
66 CompletableSubject cs = CompletableSubject.create();
67
68 Future<Void> f = cs.toFuture();
69
70 assertTrue(cs.hasObservers());
71
72 f.cancel(false);
73
74 assertFalse(cs.hasObservers());
75 }
76 }