Class FixedClock

  • All Implemented Interfaces:
    Clock

    @Beta
    public class FixedClock
    extends java.lang.Object
    implements Clock
    Beta
    A thread-safe fixed time implementation of the Clock to be used for unit testing.

    Explicitly allows you to set the time to any arbitrary value.

    Since:
    1.9
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicLong currentTime  
      • Fields inherited from interface com.google.api.client.util.Clock

        SYSTEM
    • Constructor Summary

      Constructors 
      Constructor Description
      FixedClock()
      Initializes the FixedClock with 0 millis as start time.
      FixedClock​(long startTime)
      Initializes the FixedClock with the specified time.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long currentTimeMillis()
      Returns the current time in milliseconds since midnight, January 1, 1970 UTC, to match the behavior of System.currentTimeMillis().
      FixedClock setTime​(long newTime)
      Changes the time value this time provider is returning.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • currentTime

        private java.util.concurrent.atomic.AtomicLong currentTime
    • Constructor Detail

      • FixedClock

        public FixedClock()
        Initializes the FixedClock with 0 millis as start time.
      • FixedClock

        public FixedClock​(long startTime)
        Initializes the FixedClock with the specified time.
        Parameters:
        startTime - time in milliseconds used for initialization.
    • Method Detail

      • setTime

        public FixedClock setTime​(long newTime)
        Changes the time value this time provider is returning.
        Parameters:
        newTime - New time in milliseconds.
      • currentTimeMillis

        public long currentTimeMillis()
        Description copied from interface: Clock
        Returns the current time in milliseconds since midnight, January 1, 1970 UTC, to match the behavior of System.currentTimeMillis().
        Specified by:
        currentTimeMillis in interface Clock