@Test public void doesNotApplyFunctionIfGetIsInvokedAndSuppliedVersionConstant() { when(mockVersionedSupplier.get()).thenReturn(VersionedType.of(null, 0)); assertThat(testSupplier.get()).isNull(); assertThat(counter).isEqualTo(1); when(mockVersionedSupplier.get()).thenReturn(VersionedType.of(3L, 0)); assertThat(testSupplier.get()).isNull(); assertThat(counter).isEqualTo(1); when(mockVersionedSupplier.get()).thenReturn(VersionedType.of(8L, 0)); assertThat(testSupplier.get()).isNull(); assertThat(counter).isEqualTo(1); when(mockVersionedSupplier.get()).thenReturn(VersionedType.of(3L, 1)); assertThat(testSupplier.get()).isEqualTo(6); assertThat(counter).isEqualTo(2); }
@Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier);  CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier,
            long maxTimeBetweenRecomputes, Clock clock); }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier);  CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier,
            long maxTimeBetweenRecomputes, Clock clock); @Override R get(); }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier);  CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier,
            long maxTimeBetweenRecomputes, Clock clock); @Override R get();  }