Class TestClock


  • @ThreadSafe
    public final class TestClock
    extends Clock
    A Clock that allows the time to be set for testing.
    Since:
    0.5
    • Constructor Detail

      • TestClock

        private TestClock()
    • Method Detail

      • create

        public static TestClock create()
        Creates a clock initialized to a constant non-zero time. Timestamp.create(0, 0) is not a good default, because it represents an invalid time.
        Returns:
        a clock initialized to a constant non-zero time.
        Since:
        0.5
      • create

        public static TestClock create​(Timestamp time)
        Creates a clock with the given time.
        Parameters:
        time - the initial time.
        Returns:
        a new TestClock with the given time.
        Since:
        0.5
      • setTime

        public void setTime​(Timestamp time)
        Sets the time.
        Parameters:
        time - the new time.
        Since:
        0.5
      • advanceTime

        public void advanceTime​(Duration duration)
        Advances the time by a duration.
        Parameters:
        duration - the increase in time.
        Since:
        0.5
      • now

        public Timestamp now()
        Description copied from class: Clock
        Obtains the current instant from this clock.
        Specified by:
        now in class Clock
        Returns:
        the current instant.
      • nowNanos

        public long nowNanos()
        Description copied from class: Clock
        Returns a time measurement with nanosecond precision that can only be used to calculate elapsed time.
        Specified by:
        nowNanos in class Clock
        Returns:
        a time measurement with nanosecond precision that can only be used to calculate elapsed time.
      • getNanos

        private static long getNanos​(Timestamp time)