Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/single/SingleTimestampTest.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.single;
15
16 import java.util.concurrent.TimeUnit;
17
18 import org.junit.Test;
19
20 import io.reactivex.rxjava3.core.Single;
21 import io.reactivex.rxjava3.exceptions.TestException;
22 import io.reactivex.rxjava3.observers.TestObserver;
23 import io.reactivex.rxjava3.schedulers.*;
24 import io.reactivex.rxjava3.subjects.SingleSubject;
25 import io.reactivex.rxjava3.testsupport.TestHelper;
26
27 public class SingleTimestampTest {
28
29 @Test
30 public void just() {
31 Single.just(1)
32 .timeInterval()
33 .test()
34 .assertValueCount(1)
35 .assertNoErrors()
36 .assertComplete();
37 }
38
39 @Test
40 public void error() {
41 Single.error(new TestException())
42 .timeInterval()
43 .test()
44 .assertFailure(TestException.class);
45 }
46
47 @Test
48 public void justSeconds() {
49 Single.just(1)
50 .timeInterval(TimeUnit.SECONDS)
51 .test()
52 .assertValueCount(1)
53 .assertNoErrors()
54 .assertComplete();
55 }
56
57 @Test
58 public void justScheduler() {
59 Single.just(1)
60 .timeInterval(Schedulers.single())
61 .test()
62 .assertValueCount(1)
63 .assertNoErrors()
64 .assertComplete();
65 }
66
67 @Test
68 public void justSecondsScheduler() {
69 Single.just(1)
70 .timeInterval(TimeUnit.SECONDS, Schedulers.single())
71 .test()
72 .assertValueCount(1)
73 .assertNoErrors()
74 .assertComplete();
75 }
76
77 @Test
78 public void doubleOnSubscribe() {
79 TestHelper.checkDoubleOnSubscribeSingle(m -> m.timeInterval());
80 }
81
82 @Test
83 public void dispose() {
84 TestHelper.checkDisposed(SingleSubject.create().timeInterval());
85 }
86
87 @Test
88 public void timeInfo() {
89 TestScheduler scheduler = new TestScheduler();
90
91 SingleSubject<Integer> ss = SingleSubject.create();
92
93 TestObserver<Timed<Integer>> to = ss
94 .timeInterval(scheduler)
95 .test();
96
97 scheduler.advanceTimeBy(1000, TimeUnit.MILLISECONDS);
98
99 ss.onSuccess(1);
100
101 to.assertResult(new Timed<>(1, 1000L, TimeUnit.MILLISECONDS));
102 }
103 }