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 secondchangeAmountand given parameters.MutableClock(Instant instant, ZoneId zone, TemporalAmount changeAmount)MutableClock(ZonedDateTime zonedDateTime)Initializes a with instant and zone fromZonedDateTimeand 1 secondchangeAmount.MutableClock(ZoneId zone)Initializes a withInstant.now()and given zone and 1 secondchangeAmount. -
Method Summary
Modifier and Type Method Description MutableClockadjust(TemporalAdjuster adjuster)Applies the givenTemporalAdjusterto the internal time.ZoneIdgetZone()Instantinstant()MutableClockminus(TemporalAmount amount)Subtracts the givenTemporalAmountfrom the internal time.MutableClockmodify(BiFunction<Instant,ZoneId,Instant> modification)Sets the internal time based on the result of the modification.MutableClocknext()AddschangeAmountto internal time.MutableClockplus(TemporalAmount amount)Adds the givenTemporalAmountto the internal time.MutableClockprevious()SubtractschangeAmountfrom internal time.voidsetChangeAmount(TemporalAmount changeAmount)voidsetInstant(Instant instant)StringtoString()MutableClockwithZone(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 secondchangeAmountand given parameters.- Parameters:
instant- to usezone- to use
-
MutableClock
-
MutableClock
Initializes a with instant and zone fromZonedDateTimeand 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 givenTemporalAmountto the internal time.- Parameters:
amount- to add- Returns:
- this
-
minus
Subtracts the givenTemporalAmountfrom the internal time.- Parameters:
amount- to subtract- Returns:
- this
-
adjust
Applies the givenTemporalAdjusterto the internal time.- Parameters:
adjuster- the adjuster to use,- Returns:
- this
-
next
AddschangeAmountto internal time.- Returns:
- this
-
previous
SubtractschangeAmountfrom internal time.- Returns:
- this
-
toString
-