@SuppressWarnings("unchecked") @Test void testForceRefresh() { LongSupplier currentTimeSupplier = Mockito.mock(LongSupplier.class); Mockito.when(currentTimeSupplier.getAsLong()) .thenReturn(0L, toMillis(5), toMillis(10), toMillis(15), toMillis(25)); Supplier<String> refreshFunction = Mockito.mock(Supplier.class); Mockito.when(refreshFunction.get()) .thenReturn("a", "b", "c"); CachedObject<String> cachedName = new CachedObject<>(20, currentTimeSupplier); assertEquals("a", cachedName.get(refreshFunction)); assertEquals("a", cachedName.get(refreshFunction)); assertEquals("b", cachedName.forceRefresh(refreshFunction)); assertEquals("b", cachedName.get(refreshFunction)); }
public synchronized T forceRefresh(Supplier<T> refreshFunction) { object = refreshFunction.get(); lastRefreshTime = currentTimeSupplier.getAsLong(); return object; }
CachedObject { public synchronized T forceRefresh(Supplier<T> refreshFunction) { object = refreshFunction.get(); lastRefreshTime = currentTimeSupplier.getAsLong(); return object; } }
CachedObject { public synchronized T forceRefresh(Supplier<T> refreshFunction) { object = refreshFunction.get(); lastRefreshTime = currentTimeSupplier.getAsLong(); return object; } CachedObject(long expirationTimeInSeconds);  CachedObject(long expirationTimeInSeconds, LongSupplier currentTimeSupplier); }
CachedObject { public synchronized T forceRefresh(Supplier<T> refreshFunction) { object = refreshFunction.get(); lastRefreshTime = currentTimeSupplier.getAsLong(); return object; } CachedObject(long expirationTimeInSeconds);  CachedObject(long expirationTimeInSeconds, LongSupplier currentTimeSupplier); synchronized T get(Supplier<T> refreshFunction); synchronized T forceRefresh(Supplier<T> refreshFunction); }
CachedObject { public synchronized T forceRefresh(Supplier<T> refreshFunction) { object = refreshFunction.get(); lastRefreshTime = currentTimeSupplier.getAsLong(); return object; } CachedObject(long expirationTimeInSeconds);  CachedObject(long expirationTimeInSeconds, LongSupplier currentTimeSupplier); synchronized T get(Supplier<T> refreshFunction); synchronized T forceRefresh(Supplier<T> refreshFunction);  }