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
|
* Record details from the given {@code details} map. Keys from the given map
|
||||||
* the given map will replace any existing keys if there are duplicates.
|
* replace any existing keys if there are duplicates.
|
||||||
* @param details map of details
|
* @param details map of details
|
||||||
* @return this {@link Builder} instance
|
* @return this {@link Builder} instance
|
||||||
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public Builder withDetails(Map<String, ?> details) {
|
public Builder withDetails(Map<String, ?> details) {
|
||||||
Assert.notNull(details, "Details must not be null");
|
Assert.notNull(details, "Details must not be null");
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link Health}.
|
* Tests for {@link Health}.
|
||||||
|
@ -97,59 +98,30 @@ public class HealthTests {
|
||||||
Map<String, Object> details = new LinkedHashMap<>();
|
Map<String, Object> details = new LinkedHashMap<>();
|
||||||
details.put("a", "b");
|
details.put("a", "b");
|
||||||
details.put("c", "d");
|
details.put("c", "d");
|
||||||
|
Health health = Health.up().withDetails(details).build();
|
||||||
Health.Builder builder = Health.up();
|
assertThat(health.getDetails()).containsOnly(entry("a", "b"), entry("c", "d"));
|
||||||
builder.withDetails(details);
|
|
||||||
|
|
||||||
Health health = builder.build();
|
|
||||||
assertThat(health.getDetails().get("a")).isEqualTo("b");
|
|
||||||
assertThat(health.getDetails().get("c")).isEqualTo("d");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withDetailsMapDuplicateKeys() {
|
public void withDetailsMapDuplicateKeys() {
|
||||||
Map<String, Object> details = new LinkedHashMap<>();
|
Map<String, Object> details = new LinkedHashMap<>();
|
||||||
details.put("a", "b");
|
|
||||||
details.put("c", "d");
|
details.put("c", "d");
|
||||||
details.put("a", "e");
|
details.put("a", "e");
|
||||||
|
Health health = Health.up().withDetail("a", "b").withDetails(details).build();
|
||||||
Health.Builder builder = Health.up();
|
assertThat(health.getDetails()).containsOnly(entry("a", "e"), entry("c", "d"));
|
||||||
builder.withDetails(details);
|
|
||||||
|
|
||||||
Health health = builder.build();
|
|
||||||
assertThat(health.getDetails().get("a")).isEqualTo("e");
|
|
||||||
assertThat(health.getDetails().get("c")).isEqualTo("d");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withMultipleDetailsMaps() {
|
public void withDetailsMultipleMaps() {
|
||||||
Map<String, Object> details1 = new LinkedHashMap<>();
|
Map<String, Object> details1 = new LinkedHashMap<>();
|
||||||
details1.put("a", "b");
|
details1.put("a", "b");
|
||||||
details1.put("c", "d");
|
details1.put("c", "d");
|
||||||
|
|
||||||
Map<String, Object> details2 = new LinkedHashMap<>();
|
Map<String, Object> details2 = new LinkedHashMap<>();
|
||||||
details2.put("1", "2");
|
details1.put("a", "e");
|
||||||
|
details1.put("1", "2");
|
||||||
Health.Builder builder = Health.up();
|
Health health = Health.up().withDetails(details1).withDetails(details2).build();
|
||||||
builder.withDetails(details1);
|
assertThat(health.getDetails()).containsOnly(entry("a", "e"), entry("c", "d"),
|
||||||
builder.withDetails(details2);
|
entry("1", "2"));
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue