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 aFakeTimeSourceinstance that automatically advances the time value each timenow()is called.FakeTimeSource(boolean autoAdvance)Create aFakeTimeSourceinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvance()Advance the fake value representing the "current" time by an unspecified, fixed amount.voidadvance(Duration timeToAdd)Advance the fake value representing the "current" time by a fixed amount specified by the caller.DurationelapsedSoFar()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.Instantnow()Return the fake value representing the "current" time.
-
-
-
Constructor Detail
-
FakeTimeSource
public FakeTimeSource()
Create aFakeTimeSourceinstance that automatically advances the time value each timenow()is called.
-
FakeTimeSource
public FakeTimeSource(boolean autoAdvance)
Create aFakeTimeSourceinstance.- 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:
nowin 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.
-
-