ContextPairsTests Class — spring-boot Architecture
Architecture documentation for the ContextPairsTests class in ContextPairsTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/java/org/springframework/boot/logging/structured/ContextPairsTests.java lines 34–185
class ContextPairsTests {
@Test
void flatWhenIncludeFalseDoesNothing() {
ContextPairs contextPairs = new ContextPairs(false, null);
Map<String, String> map = Map.of("spring", "boot");
Map<String, Object> actual = apply(contextPairs.flat(".", (pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).isEmpty();
}
@Test
void flatIncludesName() {
ContextPairs contextPairs = new ContextPairs(true, null);
Map<String, String> map = Map.of("spring", "boot");
Map<String, Object> actual = apply(contextPairs.flat(".", (pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).containsExactlyEntriesOf(map);
}
@Test
void flatWhenPrefixAppliesPrefix() {
ContextPairs contextPairs = new ContextPairs(true, "the");
Map<String, String> map = Map.of("spring", "boot");
Map<String, Object> actual = apply(contextPairs.flat("_", (pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).containsOnly(entry("the_spring", "boot"));
}
@Test
void flatWhenPrefixEndingWithDelimiterAppliesPrefix() {
ContextPairs contextPairs = new ContextPairs(true, "the_");
Map<String, String> map = Map.of("spring", "boot");
Map<String, Object> actual = apply(contextPairs.flat("_", (pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).containsOnly(entry("the_spring", "boot"));
}
@Test
void flatWhenPrefixAndNameStartingWithDelimiterAppliesPrefix() {
ContextPairs contextPairs = new ContextPairs(true, "the");
Map<String, String> map = Map.of("_spring", "boot");
Map<String, Object> actual = apply(contextPairs.flat("_", (pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).containsOnly(entry("the_spring", "boot"));
}
@Test
void flatWhenJoinerJoins() {
ContextPairs contextPairs = new ContextPairs(true, "the");
Map<String, String> map = Map.of("spring", "boot");
Map<String, Object> actual = apply(
contextPairs.flat((prefix, name) -> prefix + name, (pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).containsOnly(entry("thespring", "boot"));
}
@Test
void flatWhenJoinerReturnsNullFilters() {
ContextPairs contextPairs = new ContextPairs(true, "the");
Map<String, String> map = Map.of("spring", "boot");
Map<String, Object> actual = apply(
contextPairs.flat((prefix, name) -> null, (pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).isEmpty();
}
@Test
void nestedWhenIncludeFalseDoesNothing() {
ContextPairs contextPairs = new ContextPairs(false, null);
Map<String, String> map = Map.of("spring", "boot");
Map<String, Object> actual = apply(contextPairs.nested((pairs) -> pairs.addMapEntries((item) -> map)));
assertThat(actual).isEmpty();
}
@Test
void nestedExpandsNames() {
ContextPairs contextPairs = new ContextPairs(true, null);
Map<String, String> map = new LinkedHashMap<>();
map.put("a1.b1.c1", "A1B1C1");
map.put("a1.b2.c1", "A1B2C1");
map.put("a1.b1.c2", "A1B1C2");
Map<String, Object> actual = apply(contextPairs.nested((pairs) -> pairs.addMapEntries((item) -> map)));
Map<String, Object> expected = new LinkedHashMap<>();
Map<String, Object> a1 = new LinkedHashMap<>();
Map<String, Object> b1 = new LinkedHashMap<>();
Map<String, Object> b2 = new LinkedHashMap<>();
expected.put("a1", a1);
a1.put("b1", b1);
a1.put("b2", b2);
b1.put("c1", "A1B1C1");
b1.put("c2", "A1B1C2");
b2.put("c1", "A1B2C1");
assertThat(actual).isEqualTo(expected);
}
@Test
void nestedWhenNameEndsWithDelimiterDropsTrailingDelimiter() {
ContextPairs contextPairs = new ContextPairs(true, null);
Map<String, String> map = new LinkedHashMap<>();
map.put("a1.b1.", "A1B1");
Map<String, Object> actual = apply(contextPairs.nested((pairs) -> pairs.addMapEntries((item) -> map)));
Map<String, Object> expected = new LinkedHashMap<>();
Map<String, Object> a1 = new LinkedHashMap<>();
expected.put("a1", a1);
a1.put("b1", "A1B1");
assertThat(actual).isEqualTo(expected);
}
@Test
void nestedWhenDuplicateInParentThrowsException() {
ContextPairs contextPairs = new ContextPairs(true, null);
Map<String, String> map = new LinkedHashMap<>();
map.put("a1.b1.c1", "A1B1C1");
map.put("a1.b1", "A1B1");
assertThatIllegalStateException()
.isThrownBy(() -> apply(contextPairs.nested((pairs) -> pairs.addMapEntries((item) -> map))))
.withMessage("Duplicate nested pairs added under 'a1.b1'");
}
@Test
void nestedWhenDuplicateInLeafThrowsException() {
ContextPairs contextPairs = new ContextPairs(true, null);
Map<String, String> map = new LinkedHashMap<>();
map.put("a1.b1", "A1B1");
map.put("a1.b1.c1", "A1B1C1");
assertThatIllegalStateException()
.isThrownBy(() -> apply(contextPairs.nested((pairs) -> pairs.addMapEntries((item) -> map))))
.withMessage("Duplicate nested pairs added under 'a1.b1'");
}
@Test
void nestedWhenPrefixAppliesPrefix() {
ContextPairs contextPairs = new ContextPairs(true, "a1");
Map<String, String> map = new LinkedHashMap<>();
map.put("b1.c1", "A1B1C1");
map.put("b2.c1", "A1B2C1");
map.put("b1.c2", "A1B1C2");
Map<String, Object> actual = apply(contextPairs.nested((pairs) -> pairs.addMapEntries((item) -> map)));
Map<String, Object> expected = new LinkedHashMap<>();
Map<String, Object> a1 = new LinkedHashMap<>();
Map<String, Object> b1 = new LinkedHashMap<>();
Map<String, Object> b2 = new LinkedHashMap<>();
expected.put("a1", a1);
a1.put("b1", b1);
a1.put("b2", b2);
b1.put("c1", "A1B1C1");
b1.put("c2", "A1B1C2");
b2.put("c1", "A1B2C1");
assertThat(actual).isEqualTo(expected);
}
Map<String, Object> apply(BiConsumer<?, BiConsumer<String, Object>> action) {
Map<String, Object> result = new LinkedHashMap<>();
action.accept(null, result::put);
return result;
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free