HttpBasedHealthChecker implements HealthChecker { @Override public boolean isReady() { try { apiClient.getAuthApi().getAuthStatus(); logger.info("Get Auth Status succeeded."); return true; } catch (Exception e) { logger.error("Get Auth Status failed due to: " + e); return false; } } HttpBasedHealthChecker(ApiClient apiClient); @Override boolean isReady();  }
@Test public void testSuccess() throws Throwable { ApiClient apiClient = mock(RestApiClient.class); AuthApi authApi = mock(AuthRestApi.class); doReturn(authApi).when(apiClient).getAuthApi(); doReturn(new Auth()).when(authApi).getAuthStatus(); HealthChecker healthChecker = new HttpBasedHealthChecker(apiClient); boolean response = healthChecker.isReady(); assertTrue(response); }
@Test public void testFailure() throws Throwable { ApiClient apiClient = mock(RestApiClient.class); AuthApi authApi = mock(AuthRestApi.class); doReturn(authApi).when(apiClient).getAuthApi(); doThrow(new RuntimeException("Failed to get auth status")).when(authApi).getAuthStatus(); HealthChecker healthChecker = new HttpBasedHealthChecker(apiClient); boolean response = healthChecker.isReady(); assertFalse(response); }