@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); }
@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 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 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); }
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(); }
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();  }