Package spock.util.time
Class MutableClock
java.lang.Object
java.time.Clock
spock.util.time.MutableClock
public class MutableClock extends Clock
A mutable implementation of
Clock
for testing purposes.- Since:
- 2.0
-
Constructor Summary
Constructors Constructor Description MutableClock()
MutableClock(Instant instant)
Initializes a with given instant andZoneId.systemDefault()
and 1 secondchangeAmount
.MutableClock(Instant instant, ZoneId zone)
Initializes a with 1 secondchangeAmount
and given parameters.MutableClock(Instant instant, ZoneId zone, TemporalAmount changeAmount)
MutableClock(ZonedDateTime zonedDateTime)
Initializes a with instant and zone fromZonedDateTime
and 1 secondchangeAmount
.MutableClock(ZoneId zone)
Initializes a withInstant.now()
and given zone and 1 secondchangeAmount
. -
Method Summary
Modifier and Type Method Description MutableClock
adjust(TemporalAdjuster adjuster)
Applies the givenTemporalAdjuster
to the internal time.ZoneId
getZone()
Instant
instant()
MutableClock
minus(TemporalAmount amount)
Subtracts the givenTemporalAmount
from the internal time.MutableClock
modify(BiFunction<Instant,ZoneId,Instant> modification)
Sets the internal time based on the result of the modification.MutableClock
next()
AddschangeAmount
to internal time.MutableClock
plus(TemporalAmount amount)
Adds the givenTemporalAmount
to the internal time.MutableClock
previous()
SubtractschangeAmount
from internal time.void
setChangeAmount(TemporalAmount changeAmount)
void
setInstant(Instant instant)
String
toString()
MutableClock
withZone(ZoneId zone)
Methods inherited from class java.time.Clock
equals, fixed, hashCode, millis, offset, system, systemDefaultZone, systemUTC, tick, tickMillis, tickMinutes, tickSeconds
-
Constructor Details
-
MutableClock
public MutableClock() -
MutableClock
Initializes a with given instant andZoneId.systemDefault()
and 1 secondchangeAmount
.- Parameters:
instant
- to use
-
MutableClock
Initializes a withInstant.now()
and given zone and 1 secondchangeAmount
.- Parameters:
zone
- to use
-
MutableClock
Initializes a with 1 secondchangeAmount
and given parameters.- Parameters:
instant
- to usezone
- to use
-
MutableClock
-
MutableClock
Initializes a with instant and zone fromZonedDateTime
and 1 secondchangeAmount
.- Parameters:
zonedDateTime
- to use for instant and zone information
-
-
Method Details
-
getZone
-
withZone
-
instant
-
setChangeAmount
-
setInstant
-
modify
Sets the internal time based on the result of the modification.- Parameters:
modification
- a function to produce a new Instant- Returns:
- this
-
plus
Adds the givenTemporalAmount
to the internal time.- Parameters:
amount
- to add- Returns:
- this
-
minus
Subtracts the givenTemporalAmount
from the internal time.- Parameters:
amount
- to subtract- Returns:
- this
-
adjust
Applies the givenTemporalAdjuster
to the internal time.- Parameters:
adjuster
- the adjuster to use,- Returns:
- this
-
next
AddschangeAmount
to internal time.- Returns:
- this
-
previous
SubtractschangeAmount
from internal time.- Returns:
- this
-
toString
-