StateImpl implements State { @Override public HealthCode getHealth() { try { HealthResponse response = configServerApi.get("/state/v1/health", HealthResponse.class); return HealthCode.fromString(response.status.code); } catch (ConnectionException | HttpException e) { return HealthCode.DOWN; } } StateImpl(ConfigServerApi configServerApi); @Override HealthCode getHealth();  }
@Test public void testWhenUp() { HealthResponse response = new HealthResponse(); response.status.code = "up"; when(api.get(any(), any())).thenReturn(response); HealthCode code = state.getHealth(); assertEquals(HealthCode.UP, code); }
@Test public void connectException() { RuntimeException exception = ConnectionException.handleException("Error: ", new ConnectException("connection refused")); when(api.get(any(), any())).thenThrow(exception); HealthCode code = state.getHealth(); assertEquals(HealthCode.DOWN, code); }