Class FakeTicker

java.lang.Object
com.google.common.base.Ticker
com.google.common.testing.FakeTicker

@NullMarked @GwtCompatible public class FakeTicker extends com.google.common.base.Ticker
A Ticker whose value can be advanced programmatically in test.

The ticker can be configured so that the time is incremented whenever read() is called: see setAutoIncrementStep(long, java.util.concurrent.TimeUnit).

This class is thread-safe.

Since:
10.0
Author:
Jige Yu
  • Constructor Details

    • FakeTicker

      public FakeTicker()
  • Method Details

    • advance

      @CanIgnoreReturnValue public FakeTicker advance(long time, TimeUnit timeUnit)
      Advances the ticker value by time in timeUnit.
    • advance

      @CanIgnoreReturnValue public FakeTicker advance(long nanoseconds)
      Advances the ticker value by nanoseconds.
    • advance

      @GwtIncompatible @CanIgnoreReturnValue @Beta public FakeTicker advance(Duration duration)
      Advances the ticker value by duration.
      Since:
      33.1.0 (but since 28.0 in the JRE flavor)
    • setAutoIncrementStep

      @CanIgnoreReturnValue public FakeTicker setAutoIncrementStep(long autoIncrementStep, TimeUnit timeUnit)
      Sets the increment applied to the ticker whenever it is queried.

      The default behavior is to auto increment by zero. i.e: The ticker is left unchanged when queried.

    • setAutoIncrementStep

      @GwtIncompatible @CanIgnoreReturnValue @Beta public FakeTicker setAutoIncrementStep(Duration autoIncrementStep)
      Sets the increment applied to the ticker whenever it is queried.

      The default behavior is to auto increment by zero. i.e: The ticker is left unchanged when queried.

      Since:
      33.1.0 (but since 28.0 in the JRE flavor)
    • read

      public long read()
      Specified by:
      read in class com.google.common.base.Ticker