Refactor HealthCheckTest
package com.baeldung.metrics.healthchecks;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
+import com.codahale.metrics.health.HealthCheck;
+import com.codahale.metrics.health.HealthCheckRegistry;
+import org.junit.Test;
import java.util.Map;
-import org.junit.Test;
-
-import com.codahale.metrics.health.HealthCheck;
-import com.codahale.metrics.health.HealthCheckRegistry;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
public class HealthCheckTest {
+
@Test
public void whenUseHealthCheck_thenHealthChecked() {
HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
@@ -21,9 +23,8 @@ public class HealthCheckTest {
assertThat(healthCheckRegistry.getNames().size(), equalTo(2));
Map<String, HealthCheck.Result> results = healthCheckRegistry.runHealthChecks();
- for (Map.Entry<String, HealthCheck.Result> entry : results.entrySet()) {
- assertThat(entry.getValue().isHealthy(), equalTo(true));
- }
+ assertFalse(results.isEmpty());
+ results.forEach((k, v) -> assertTrue(v.isHealthy()));
healthCheckRegistry.unregister("uc");
assertThat(healthCheckRegistry.getNames().size(), equalTo(1));
