From 8400b841e922582d685bb0ec73323bac383228bd Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Thu, 27 May 2021 16:16:24 -0500 Subject: [PATCH] Improve XsdDocumentedTests Error Message This makes it easier to compare the expected and actual values. Closes gh-9829 --- .../config/doc/XsdDocumentedTests.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java b/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java index fc57a11a188..ec4c1a8ebad 100644 --- a/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java +++ b/config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java @@ -22,10 +22,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -185,8 +185,8 @@ public void countReferencesWhenReviewingDocumentationThenEntireSchemaIsIncluded( */ @Test public void countLinksWhenReviewingDocumentationThenParentsAndChildrenAreCorrectlyLinked() throws IOException { - Map> docAttrNameToChildren = new HashMap<>(); - Map> docAttrNameToParents = new HashMap<>(); + Map> docAttrNameToChildren = new TreeMap<>(); + Map> docAttrNameToParents = new TreeMap<>(); String docAttrName = null; Map> currentDocAttrNameToElmt = null; List lines = Files.readAllLines(Paths.get(this.referenceLocation)); @@ -215,8 +215,8 @@ else if (docAttrName != null && !id.startsWith(docAttrName)) { } } Map elementNameToElement = this.xml.elementsByElementName(this.schemaDocumentLocation); - Map> schemaAttrNameToChildren = new HashMap<>(); - Map> schemaAttrNameToParents = new HashMap<>(); + Map> schemaAttrNameToChildren = new TreeMap<>(); + Map> schemaAttrNameToParents = new TreeMap<>(); elementNameToElement.entrySet().stream().forEach((entry) -> { String key = "nsa-" + entry.getKey(); if (this.ignoredIds.contains(key)) { @@ -248,8 +248,23 @@ else if (docAttrName != null && !id.startsWith(docAttrName)) { schemaAttrNameToChildren.put(key, childIds); } }); - assertThat(docAttrNameToChildren).isEqualTo(schemaAttrNameToChildren); - assertThat(docAttrNameToParents).isEqualTo(schemaAttrNameToParents); + assertThat(docAttrNameToChildren) + .describedAs(toString(docAttrNameToChildren) + "\n!=\n\n" + toString(schemaAttrNameToChildren)) + .containsExactlyInAnyOrderEntriesOf(schemaAttrNameToChildren); + assertThat(docAttrNameToParents) + .describedAs(toString(docAttrNameToParents) + "\n!=\n\n" + toString(schemaAttrNameToParents)) + .containsExactlyInAnyOrderEntriesOf(schemaAttrNameToParents); + } + + private String toString(Map map) { + StringBuffer buffer = new StringBuffer(); + map.forEach((k, v) -> { + buffer.append(k); + buffer.append("="); + buffer.append(v); + buffer.append("\n"); + }); + return buffer.toString(); } /**