AsyncHealthCheckDecorator extends HealthCheck implements Runnable { @Override protected Result check() throws Exception { long expiration = clock.getTime() - result.getTime() - healthyTtl; if (expiration > 0) { return Result.builder() .unhealthy() .usingClock(clock) .withMessage("Result was %s but it expired %d milliseconds ago", result.isHealthy() ? "healthy" : "unhealthy", expiration) .build(); } return result; } AsyncHealthCheckDecorator(HealthCheck healthCheck, ScheduledExecutorService executorService, Clock clock);   AsyncHealthCheckDecorator(HealthCheck healthCheck, ScheduledExecutorService executorService); @Override void run(); HealthCheck getHealthCheck();  }
@Test public void unhealthyAsyncHealthCheckTriggersSuccessfulInstantiationWithUnhealthyState() throws Exception { HealthCheck asyncHealthCheck = new UnhealthyAsyncHealthCheck(); AsyncHealthCheckDecorator asyncDecorator = new AsyncHealthCheckDecorator(asyncHealthCheck, mockExecutorService); assertThat(asyncDecorator.check().isHealthy()).isFalse(); }