Class FakeTimeSource
- java.lang.Object
-
- com.pervasivecode.utils.time.testing.FakeTimeSource
-
- All Implemented Interfaces:
TimeSource
public class FakeTimeSource extends Object implements TimeSource
This is a fake implementation ofTimeSource
, intended for use by test code.
-
-
Constructor Summary
Constructors Constructor Description FakeTimeSource()
Create aFakeTimeSource
instance that automatically advances the time value each timenow()
is called.FakeTimeSource(boolean autoAdvance)
Create aFakeTimeSource
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advance()
Advance the fake value representing the "current" time by an unspecified, fixed amount.void
advance(Duration timeToAdd)
Advance the fake value representing the "current" time by a fixed amount specified by the caller.Duration
elapsedSoFar()
Return the amount of time between the internal initial fake time value when this instance was created, and the internal current fake time value stored by this instance.Instant
now()
Return the fake value representing the "current" time.
-
-
-
Constructor Detail
-
FakeTimeSource
public FakeTimeSource()
Create aFakeTimeSource
instance that automatically advances the time value each timenow()
is called.
-
FakeTimeSource
public FakeTimeSource(boolean autoAdvance)
Create aFakeTimeSource
instance.- Parameters:
autoAdvance
- whether this instance should automatically advance the time value each timenow()
is called.
-
-
Method Detail
-
now
public Instant now()
Return the fake value representing the "current" time.If this instance was created with the option to automatically advance the current time, it will do so; otherwise, the current time will not be changed by calling this method.
- Specified by:
now
in interfaceTimeSource
- Returns:
- The current time.
-
advance
public void advance()
Advance the fake value representing the "current" time by an unspecified, fixed amount.
-
advance
public void advance(Duration timeToAdd)
Advance the fake value representing the "current" time by a fixed amount specified by the caller.- Parameters:
timeToAdd
- The amount of time to advance the fake value representing the "current" time.
-
elapsedSoFar
public Duration elapsedSoFar()
Return the amount of time between the internal initial fake time value when this instance was created, and the internal current fake time value stored by this instance.- Returns:
- The difference between the fake start time and the fake current time.
-
-