in util/src/main/java/com/spotify/hamcrest/util/DescriptionUtils.java [92:122]
public static void describeNestedMismatches(
Set<String> allKeys,
Description mismatchDescription,
Map<String, Consumer<Description>> mismatchedKeys,
BiConsumer<String, Description> describeKey) {
checkArgument(!mismatchedKeys.isEmpty(), "mismatchKeys must not be empty");
String previousMismatchKey = null;
String previousKey = null;
mismatchDescription.appendText("{\n");
for (String key : allKeys) {
if (mismatchedKeys.containsKey(key)) {
// If this is not the first key and the previous key was not a mismatch then add ellipsis
if (previousKey != null && !Objects.equals(previousMismatchKey, previousKey)) {
mismatchDescription.appendText(" ...\n");
}
describeMismatchForKey(key, mismatchDescription, describeKey, mismatchedKeys.get(key));
previousMismatchKey = key;
}
previousKey = key;
}
// If the last element was not a mismatch then add ellipsis
if (!Objects.equals(previousMismatchKey, previousKey)) {
mismatchDescription.appendText(" ...\n");
}
mismatchDescription.appendText("}");
}