Class FakeTimeSource

  • All Implemented Interfaces:
    TimeSource

    public class FakeTimeSource
    extends Object
    implements TimeSource
    This is a fake implementation of TimeSource, intended for use by test code.
    • Constructor Detail

      • FakeTimeSource

        public FakeTimeSource()
        Create a FakeTimeSource instance that automatically advances the time value each time now() is called.
      • FakeTimeSource

        public FakeTimeSource​(boolean autoAdvance)
        Create a FakeTimeSource instance.
        Parameters:
        autoAdvance - whether this instance should automatically advance the time value each time now() 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 interface TimeSource
        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.