DatabaseConnectionHealthCheck extends HealthCheck { @Override protected Result check() { try { healthCheckService.checkDatabaseConnection(); return HealthCheck.Result.healthy("Connection to nFlow database is OK."); } catch(Exception e) { return HealthCheck.Result.unhealthy(e); } } DatabaseConnectionHealthCheck(HealthCheckService healthCheckService);   }
@Test public void whenConnectingToDatabaseHealthCheckReturnsHealthly() { when(healthCheckService.checkDatabaseConnection()).thenReturn(true); assertEquals(true, check.check().isHealthy()); }
@Test public void whenNotConnectingToDatabaseHealthCheckReturnsUnhealthly() { RuntimeException exception = new RuntimeException("test-exception"); when(healthCheckService.checkDatabaseConnection()).thenThrow(exception); HealthCheck.Result result = check.check(); assertEquals(false, result.isHealthy()); assertEquals(exception, result.getError()); }