public final class Clock extends Object
System.currentTimeMillis()
or for testing
purposes, it can be an internal source whose time can be manipulated.
Use of this facade allows applications sensitive to time-related context to be easily unit tested under simulated and accelerated time-lines.
Modifier and Type | Class and Description |
---|---|
static interface |
Clock.WarpingTimeSource
Facade for implementing a time source capable of being warped with respect to real time.
|
Modifier and Type | Method and Description |
---|---|
static void |
assertRealTimeSource()
Sets the time-source to one backed by
System.currentTimeMillis() and asserts that no other
time-source has been previously set. |
static void |
assertTestTimeSource()
Sets the time-source to one capable of being warped relative to the
System.currentTimeMillis() and asserts that no other
time-source has been previously set. |
static long |
currentTimeMillis()
Get the current time in milliseconds since start of epoch.
|
static Date |
date()
Get the date corresponding to the current time of the source.
|
static Clock.WarpingTimeSource |
source()
Get the current time source, which may be capable of time-warping
|
public static void assertRealTimeSource() throws IllegalStateException
System.currentTimeMillis()
and asserts that no other
time-source has been previously set.
Calling this method multiple times has no side effects.
IllegalStateException
- if a time-source, other than has been
previously latchedpublic static void assertTestTimeSource()
System.currentTimeMillis()
and asserts that no other
time-source has been previously set.
Calling this method multiple times has no side effects.
IllegalStateException
- if a time-source, other than this one
has been previously latchespublic static Clock.WarpingTimeSource source()
public static long currentTimeMillis()
System.currentTimeMillis()
public static Date date()
System.currentTimeMillis()
,
Date.Date(long)
Copyright © 2015. All Rights Reserved.