Just find the answer yourself
Ticker can be used to skip time, but not expiration time.
class FakeTicker extends Ticker { private final AtomicLong nanos = new AtomicLong(); public FakeTicker advance(long time, TimeUnit timeUnit) { nanos.addAndGet(timeUnit.toNanos(time)); return this; } @Override public long read() { long value = nanos.getAndAdd(0); System.out.println("is called " + value); return value; } }
@Test public void expireAfterWriteTestWithTicker() throws InterruptedException { FakeTicker t = new FakeTicker();
source share