MemoryHealthIndicator implements HealthIndicator { @Override public Health health() { if (getAvailableMemoryPercentageCurrently() > threshold) { return Health.up().withDetail("threshold", threshold).build(); } else { return Health.down().withDetail("threshold", threshold).build(); } } MemoryHealthIndicator(double threshold); double getThreshold(); @Override Health health();  }
@Test public void shouldReturnUpWhenEnoughAvailableMemory() { final double availablePercentageCurrently = getAvailablePercentageCurrently(); final double thresholdBelowCurrentLevel = availablePercentageCurrently * 0.9; final MemoryHealthIndicator sutHealthIndicator = new MemoryHealthIndicator(thresholdBelowCurrentLevel); final Health actual = sutHealthIndicator.health(); Assertions.assertThat(actual.getStatus()).isSameAs(Status.UP); }
@Test public void shouldReturnDownWhenNotEnoughAvailableMemory() { final double availablePercentageCurrently = getAvailablePercentageCurrently(); final double thresholdAboveCurrentLevel = ((1 - availablePercentageCurrently) * 0.1) + availablePercentageCurrently; final MemoryHealthIndicator sutHealthIndicator = new MemoryHealthIndicator(thresholdAboveCurrentLevel); final Health actual = sutHealthIndicator.health(); Assertions.assertThat(actual.getStatus()).isSameAs(Status.DOWN); }