@Test public void cacheResultOnceShouldCacheOnce() { final HealthCheckResult expectedFirstResult = failure("message for failure"); final HealthCheckResult expectedSecondResult = failure("some other message"); final HealthCheckProvider mockProvider = mock(HealthCheckProvider.class); when(mockProvider.get()).thenReturn(expectedSecondResult); final HealthCheckProvider testedProvider = HealthChecks.cacheResultOnce(mockProvider, expectedFirstResult); assertEquals("first result does not match", expectedFirstResult, testedProvider.get()); assertEquals("second result does not match", expectedSecondResult, testedProvider.get()); assertEquals("third result does not match", expectedSecondResult, testedProvider.get()); }
public static HealthCheckProvider cacheResultOnce(HealthCheckProvider provider, HealthCheckResult cachedOnceResult) { return new HealthCheckProvider() { private HealthCheckResult cachedResult = cachedOnceResult; @Override public HealthCheckResult get() { HealthCheckResult result = Optional.ofNullable(cachedResult).orElseGet(provider); cachedResult = null; return result; } }; }
HealthChecks { public static HealthCheckProvider cacheResultOnce(HealthCheckProvider provider, HealthCheckResult cachedOnceResult) { return new HealthCheckProvider() { private HealthCheckResult cachedResult = cachedOnceResult; @Override public HealthCheckResult get() { HealthCheckResult result = Optional.ofNullable(cachedResult).orElseGet(provider); cachedResult = null; return result; } }; } }
HealthChecks { public static HealthCheckProvider cacheResultOnce(HealthCheckProvider provider, HealthCheckResult cachedOnceResult) { return new HealthCheckProvider() { private HealthCheckResult cachedResult = cachedOnceResult; @Override public HealthCheckResult get() { HealthCheckResult result = Optional.ofNullable(cachedResult).orElseGet(provider); cachedResult = null; return result; } }; } private  HealthChecks(); }
HealthChecks { public static HealthCheckProvider cacheResultOnce(HealthCheckProvider provider, HealthCheckResult cachedOnceResult) { return new HealthCheckProvider() { private HealthCheckResult cachedResult = cachedOnceResult; @Override public HealthCheckResult get() { HealthCheckResult result = Optional.ofNullable(cachedResult).orElseGet(provider); cachedResult = null; return result; } }; } private  HealthChecks(); static HealthCheckProvider checkAuthKeyOcspStatus(); static HealthCheckProvider checkServerConfDatabaseStatus(); static Function<HealthCheckProvider, HealthCheckProvider> cacheResultFor(
            int resultValidFor, int errorResultValidFor, TimeUnit timeUnit); static HealthCheckProvider cacheResultOnce(HealthCheckProvider provider,
                                                      HealthCheckResult cachedOnceResult); }
HealthChecks { public static HealthCheckProvider cacheResultOnce(HealthCheckProvider provider, HealthCheckResult cachedOnceResult) { return new HealthCheckProvider() { private HealthCheckResult cachedResult = cachedOnceResult; @Override public HealthCheckResult get() { HealthCheckResult result = Optional.ofNullable(cachedResult).orElseGet(provider); cachedResult = null; return result; } }; } private  HealthChecks(); static HealthCheckProvider checkAuthKeyOcspStatus(); static HealthCheckProvider checkServerConfDatabaseStatus(); static Function<HealthCheckProvider, HealthCheckProvider> cacheResultFor(
            int resultValidFor, int errorResultValidFor, TimeUnit timeUnit); static HealthCheckProvider cacheResultOnce(HealthCheckProvider provider,
                                                      HealthCheckResult cachedOnceResult);  }