public final class ControllableClock extends Clock implements TimeControllable, Serializable
Clock, typically intended for use in testing. A ControllableClock
may either be freely running (as e.g. the system clock) or freezed, and can in all cases be set
to a new point in time.| Modifier and Type | Method and Description |
|---|---|
static ControllableClock |
control(Clock clock)
Create a controllable clock based on an existing clock.
|
boolean |
equals(Object obj) |
void |
freeze()
Signal that time should freeze.
|
static ControllableClock |
freezedAt(Instant instant)
Create a new controllable clock freezed at a given instant,
and with the
default time zone. |
static ControllableClock |
freezedAt(Instant instant,
ZoneId zone)
|
static ControllableClock |
freezedAt(LocalDateTime dateTime)
Create a new controllable clock freezed at the instant resolved from a given
LocalDateTime and the default time zone. |
static ControllableClock |
freezedAt(ZonedDateTime dateTime)
Create a new controllable clock freezed at the instant of a given
ZonedDateTime. |
ZoneId |
getZone() |
int |
hashCode() |
Instant |
instant() |
void |
set(Clock newDelegate) |
void |
set(Instant newInstant)
Set the time to the given instant.
|
void |
set(LocalDateTime dateTime)
Set the time to the given local date and time.
|
void |
setToSystemClock()
Set the time to freely progressing system time.
|
void |
setToSystemClock(ZoneId zoneId) |
void |
timePasses(Duration duration)
Signal that time is passing a given amount of time.
|
void |
timePasses(TemporalAmount amountOfTime)
Signal that time is passing a given amount of time.
|
String |
toString() |
ControllableClock |
withZone(ZoneId zone) |
fixed, millis, offset, system, systemDefaultZone, systemUTC, tick, tickMinutes, tickSecondsclone, finalize, getClass, notify, notifyAll, wait, wait, waitsetpublic static ControllableClock freezedAt(LocalDateTime dateTime)
LocalDateTime and the default time zone.
The clock will not progress on its own, and will yield the instant
it is set to.dateTime - The date and time to set for the new freezed clock.ControllableClockpublic static ControllableClock freezedAt(ZonedDateTime dateTime)
ZonedDateTime.
The clock will not progress on its own, and will yield the instant
it is set to.dateTime - The date and time to set for the new freezed clock.ControllableClockpublic static ControllableClock freezedAt(Instant instant)
default time zone.
The clock will not progress on its own, and will yield the instant
it is set to.instant - The instant to set for the new freezed clock.ControllableClockpublic static ControllableClock freezedAt(Instant instant, ZoneId zone)
Instant, and with a given ZoneId.
The clock will not progress on its own, and will yield a set instant.instant - The instant to set for the new freezed clock.zone - The time zone of the new freezed clock.ControllableClockpublic static ControllableClock control(Clock clock)
ControllableClock will have the same behavior (freezed or progressing)
and time as the given clock, but may be mutated to yield another instant, or
be freezed. The given clock is of course not altered.clock - The clock to base the new ControllableClock instance on.ControllableClockpublic ControllableClock withZone(ZoneId zone)
public void timePasses(TemporalAmount amountOfTime)
TimeControllabletimePasses in interface TimeControllableamountOfTime - the amount of time which are passing.public void timePasses(Duration duration)
TimeControllabletimePasses in interface TimeControllablepublic void set(LocalDateTime dateTime)
TimeControllableset in interface TimeControllabledateTime - the date and time to set.public void set(Instant newInstant)
TimeControllableset in interface TimeControllablenewInstant - the instant to set.public void set(Clock newDelegate)
public void freeze()
TimeControllablefreeze in interface TimeControllablepublic void setToSystemClock()
TimeControllablesetToSystemClock in interface TimeControllableClock.system(ZoneId)public void setToSystemClock(ZoneId zoneId)
Copyright © 2018 Digipost. All rights reserved.