NamedHealthCheck extends HealthCheck { @Override public Result execute() { try { Result result = check(); if (!result.isHealthy()) { logger.log(Level.WARNING, "HealthCheck '{0}' is unhealthy: {1}", new Object[]{getName(), result.getMessage()}); } return result; } catch (Exception e) { logger.log(Level.WARNING, "Exception in health check: {0}", new Object[]{getName(), e}); return Result.unhealthy(e); } } protected  NamedHealthCheck(); protected  NamedHealthCheck(final String name); protected  NamedHealthCheck(String name, Logger logger); String getName(); @Override Result execute();  }
@Test public void checkHealthy() { result = HealthCheck.Result.healthy(); assertThat(healthCheck.execute().isHealthy(), is(true)); }
@Test public void checkUnhealthy() { result = HealthCheck.Result.unhealthy("ill"); assertThat(healthCheck.execute().isHealthy(), is(false)); Mockito.verify(logger, Mockito.times(1)).log(eq(Level.WARNING), anyObject(), (Object[]) anyObject()); }
@Test public void checkUnhealthyWithException() { result = HealthCheck.Result.unhealthy("ill"); assertThat(healthCheckException.execute().isHealthy(), is(false)); Mockito.verify(logger, Mockito.times(1)).log(eq(Level.WARNING), anyObject(), (Object[]) anyObject()); }