Polish "Add Health details using maps"

Closes gh-14305
pull/14312/head
Stephane Nicoll 6 years ago
parent 5c86f9eca4
commit ca8be3f6bd

@ -231,10 +231,11 @@ public final class Health {
}
/**
* Add details from the given {@code details} map into existing details. Keys from
* the given map will replace any existing keys if there are duplicates.
* Record details from the given {@code details} map. Keys from the given map
* replace any existing keys if there are duplicates.
* @param details map of details
* @return this {@link Builder} instance
* @since 2.1.0
*/
public Builder withDetails(Map<String, ?> details) {
Assert.notNull(details, "Details must not be null");

@ -25,6 +25,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
/**
* Tests for {@link Health}.
@ -97,59 +98,30 @@ public class HealthTests {
Map<String, Object> details = new LinkedHashMap<>();
details.put("a", "b");
details.put("c", "d");
Health.Builder builder = Health.up();
builder.withDetails(details);
Health health = builder.build();
assertThat(health.getDetails().get("a")).isEqualTo("b");
assertThat(health.getDetails().get("c")).isEqualTo("d");
Health health = Health.up().withDetails(details).build();
assertThat(health.getDetails()).containsOnly(entry("a", "b"), entry("c", "d"));
}
@Test
public void withDetailsMapDuplicateKeys() {
Map<String, Object> details = new LinkedHashMap<>();
details.put("a", "b");
details.put("c", "d");
details.put("a", "e");
Health.Builder builder = Health.up();
builder.withDetails(details);
Health health = builder.build();
assertThat(health.getDetails().get("a")).isEqualTo("e");
assertThat(health.getDetails().get("c")).isEqualTo("d");
Health health = Health.up().withDetail("a", "b").withDetails(details).build();
assertThat(health.getDetails()).containsOnly(entry("a", "e"), entry("c", "d"));
}
@Test
public void withMultipleDetailsMaps() {
public void withDetailsMultipleMaps() {
Map<String, Object> details1 = new LinkedHashMap<>();
details1.put("a", "b");
details1.put("c", "d");
Map<String, Object> details2 = new LinkedHashMap<>();
details2.put("1", "2");
Health.Builder builder = Health.up();
builder.withDetails(details1);
builder.withDetails(details2);
Health health = builder.build();
assertThat(health.getDetails().get("a")).isEqualTo("b");
assertThat(health.getDetails().get("c")).isEqualTo("d");
assertThat(health.getDetails().get("1")).isEqualTo("2");
}
@Test
public void mixWithDetailsUsage() {
Map<String, Object> details = new LinkedHashMap<>();
details.put("a", "b");
Health.Builder builder = Health.up().withDetails(details).withDetail("c", "d");
Health health = builder.build();
assertThat(health.getDetails().get("a")).isEqualTo("b");
assertThat(health.getDetails().get("c")).isEqualTo("d");
details1.put("a", "e");
details1.put("1", "2");
Health health = Health.up().withDetails(details1).withDetails(details2).build();
assertThat(health.getDetails()).containsOnly(entry("a", "e"), entry("c", "d"),
entry("1", "2"));
}
@Test

Loading…
Cancel
Save