Debian Codegraph @

src/test/java/io/reactivex/rxjava3/schedulers/TimedTest.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.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
24 public class TimedTest extends RxJavaTest {
25
26 @Test
27 public void properties() {
28 Timed<Integer> timed = new Timed<>(1, 5, TimeUnit.SECONDS);
29
30 assertEquals(1, timed.value().intValue());
31 assertEquals(5, timed.time());
32 assertEquals(5000, timed.time(TimeUnit.MILLISECONDS));
33 assertSame(TimeUnit.SECONDS, timed.unit());
34 }
35
36 @Test
37 public void hashCodeOf() {
38 Timed<Integer> t1 = new Timed<>(1, 5, TimeUnit.SECONDS);
39
40 assertEquals(TimeUnit.SECONDS.hashCode() + 31 * (5 + 31 * 1), t1.hashCode());
41
42 Timed<Integer> t2 = new Timed<>(0, 5, TimeUnit.SECONDS);
43
44 assertEquals(TimeUnit.SECONDS.hashCode() + 31 * (5 + 31 * 0), t2.hashCode());
45 }
46
47 @Test
48 public void equalsWith() {
49 Timed<Integer> t1 = new Timed<>(1, 5, TimeUnit.SECONDS);
50 Timed<Integer> t2 = new Timed<>(1, 5, TimeUnit.SECONDS);
51 Timed<Integer> t3 = new Timed<>(2, 5, TimeUnit.SECONDS);
52 Timed<Integer> t4 = new Timed<>(1, 4, TimeUnit.SECONDS);
53 Timed<Integer> t5 = new Timed<>(1, 5, TimeUnit.MINUTES);
54
55 assertEquals(t1, t1);
56 assertEquals(t1, t2);
57
58 assertNotEquals(t1, t3);
59 assertNotEquals(t1, t4);
60 assertNotEquals(t2, t3);
61 assertNotEquals(t2, t4);
62 assertNotEquals(t2, t5);
63
64 assertNotEquals(t3, t1);
65 assertNotEquals(t3, t2);
66 assertNotEquals(t3, t4);
67 assertNotEquals(t3, t5);
68
69 assertNotEquals(t4, t1);
70 assertNotEquals(t4, t2);
71 assertNotEquals(t4, t3);
72 assertNotEquals(t4, t5);
73
74 assertNotEquals(t5, t1);
75 assertNotEquals(t5, t2);
76 assertNotEquals(t5, t3);
77 assertNotEquals(t5, t4);
78
79 assertNotEquals(new Object(), t1);
80
81 assertNotEquals(t1, new Object());
82 }
83
84 @Test
85 public void toStringOf() {
86 Timed<Integer> t1 = new Timed<>(1, 5, TimeUnit.SECONDS);
87
88 assertEquals("Timed[time=5, unit=SECONDS, value=1]", t1.toString());
89 }
90
91 @Test(expected = NullPointerException.class)
92 public void timeUnitNullFail() throws Exception {
93 new Timed<>(1, 5, null);
94 }
95 }