DiskSpaceCheckerHealthCheck extends HealthCheck { @Override protected Result check() throws Exception { try { if (checker.isSpaceAvailable()) { return Result.healthy(); } else { return Result.unhealthy("DiskSpaceChecker returns no space available"); } } catch (DiskSpaceCheckerException e) { LOGGER.warn("DiskSpaceChecker threw exception during healthcheck: {}", e.getMessage()); return Result.unhealthy(e); } } DiskSpaceCheckerHealthCheck(DiskSpaceChecker checker);   }
@Test public void returnsUnhealthyWhenCheckerThrowsException() throws Exception { when(checker.isSpaceAvailable()).thenThrow(new DiskSpaceCheckerException("Error")); Result result = healthCheck.check(); assertThat(result.isHealthy()).isFalse(); }
@Test public void returnsUnhealthyWhenCheckerFails() throws Exception { when(checker.isSpaceAvailable()).thenReturn(false); Result result = healthCheck.check(); assertThat(result.isHealthy()).isFalse(); }
@Test public void returnsHealthyWhenCheckerPasses() throws Exception { when(checker.isSpaceAvailable()).thenReturn(true); Result result = healthCheck.check(); assertThat(result.isHealthy()).isTrue(); }