Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/schedulers/ImmediateThinSchedulerTest.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.schedulers;
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.core.Scheduler.Worker;
24 import io.reactivex.rxjava3.internal.functions.Functions;
25
26 public class ImmediateThinSchedulerTest extends RxJavaTest {
27
28 @Test
29 public void scheduleDirect() {
30 final int[] count = { 0 };
31
32 ImmediateThinScheduler.INSTANCE.scheduleDirect(new Runnable() {
33 @Override
34 public void run() {
35 count[0]++;
36 }
37 });
38
39 assertEquals(1, count[0]);
40 }
41
42 @Test(expected = UnsupportedOperationException.class)
43 public void scheduleDirectTimed() {
44 ImmediateThinScheduler.INSTANCE.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.SECONDS);
45 }
46
47 @Test(expected = UnsupportedOperationException.class)
48 public void scheduleDirectPeriodic() {
49 ImmediateThinScheduler.INSTANCE.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 1, 1, TimeUnit.SECONDS);
50 }
51
52 @Test
53 public void schedule() {
54 final int[] count = { 0 };
55
56 Worker w = ImmediateThinScheduler.INSTANCE.createWorker();
57
58 assertFalse(w.isDisposed());
59
60 w.schedule(new Runnable() {
61 @Override
62 public void run() {
63 count[0]++;
64 }
65 });
66
67 assertEquals(1, count[0]);
68 }
69
70 @Test(expected = UnsupportedOperationException.class)
71 public void scheduleTimed() {
72 ImmediateThinScheduler.INSTANCE.createWorker().schedule(Functions.EMPTY_RUNNABLE, 1, TimeUnit.SECONDS);
73 }
74
75 @Test(expected = UnsupportedOperationException.class)
76 public void schedulePeriodic() {
77 ImmediateThinScheduler.INSTANCE.createWorker().schedulePeriodically(Functions.EMPTY_RUNNABLE, 1, 1, TimeUnit.SECONDS);
78 }
79 }