Debian Codegraph @

src/test/java/io/reactivex/rxjava3/disposables/FutureDisposableTest.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.disposables;
15
16 import static org.junit.Assert.*;
17
18 import java.util.concurrent.FutureTask;
19
20 import org.junit.Test;
21
22 import io.reactivex.rxjava3.core.RxJavaTest;
23 import io.reactivex.rxjava3.internal.functions.Functions;
24
25 public class FutureDisposableTest extends RxJavaTest {
26
27 @Test
28 public void normal() {
29 FutureTask<Object> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
30 Disposable d = Disposable.fromFuture(ft);
31 assertFalse(d.isDisposed());
32
33 d.dispose();
34
35 assertTrue(d.isDisposed());
36
37 d.dispose();
38
39 assertTrue(d.isDisposed());
40
41 assertTrue(ft.isCancelled());
42 }
43
44 @Test
45 public void interruptible() {
46 FutureTask<Object> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
47 Disposable d = Disposable.fromFuture(ft, true);
48 assertFalse(d.isDisposed());
49
50 d.dispose();
51
52 assertTrue(d.isDisposed());
53
54 d.dispose();
55
56 assertTrue(d.isDisposed());
57
58 assertTrue(ft.isCancelled());
59 }
60
61 @Test
62 public void normalDone() {
63 FutureTask<Object> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
64 FutureDisposable d = new FutureDisposable(ft, false);
65 assertFalse(d.isDisposed());
66
67 assertFalse(d.isDisposed());
68
69 ft.run();
70
71 assertTrue(d.isDisposed());
72 }
73 }