File tree 2 files changed +25
-1
lines changed
main/java/io/reactivex/schedulers
test/java/io/reactivex/schedulers
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,25 @@ public final class TestScheduler extends Scheduler {
35
35
// Storing time in nanoseconds internally.
36
36
volatile long time ;
37
37
38
+ /**
39
+ * Creates a new TestScheduler with initial virtual time of zero.
40
+ */
41
+ public TestScheduler () {
42
+ // No-op.
43
+ }
44
+
45
+ /**
46
+ * Creates a new TestScheduler with the specified initial virtual time.
47
+ *
48
+ * @param delayTime
49
+ * the point in time to move the Scheduler's clock to
50
+ * @param unit
51
+ * the units of time that {@code delayTime} is expressed in
52
+ */
53
+ public TestScheduler (long delayTime , TimeUnit unit ) {
54
+ time = unit .toNanos (delayTime );
55
+ }
56
+
38
57
static final class TimedRunnable implements Comparable <TimedRunnable > {
39
58
40
59
final long time ;
Original file line number Diff line number Diff line change @@ -253,5 +253,10 @@ public void workerDisposed() {
253
253
assertTrue (w .isDisposed ());
254
254
}
255
255
256
-
256
+ @ Test
257
+ public void constructorTimeSetsTime () {
258
+ TestScheduler ts = new TestScheduler (5 , TimeUnit .SECONDS );
259
+ assertEquals (5 , ts .now (TimeUnit .SECONDS ));
260
+ assertEquals (5000 , ts .now (TimeUnit .MILLISECONDS ));
261
+ }
257
262
}
You can’t perform that action at this time.
0 commit comments