Skip to content

Commit

Permalink
Improve XsdDocumentedTests Error Message
Browse files Browse the repository at this point in the history
This makes it easier to compare the expected and actual values.

Closes gh-9829
  • Loading branch information
rwinch committed May 27, 2021
1 parent 65ecaa0 commit 8400b84
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -185,8 +185,8 @@ public void countReferencesWhenReviewingDocumentationThenEntireSchemaIsIncluded(
*/
@Test
public void countLinksWhenReviewingDocumentationThenParentsAndChildrenAreCorrectlyLinked() throws IOException {
Map<String, List<String>> docAttrNameToChildren = new HashMap<>();
Map<String, List<String>> docAttrNameToParents = new HashMap<>();
Map<String, List<String>> docAttrNameToChildren = new TreeMap<>();
Map<String, List<String>> docAttrNameToParents = new TreeMap<>();
String docAttrName = null;
Map<String, List<String>> currentDocAttrNameToElmt = null;
List<String> lines = Files.readAllLines(Paths.get(this.referenceLocation));
Expand Down Expand Up @@ -215,8 +215,8 @@ else if (docAttrName != null && !id.startsWith(docAttrName)) {
}
}
Map<String, Element> elementNameToElement = this.xml.elementsByElementName(this.schemaDocumentLocation);
Map<String, List<String>> schemaAttrNameToChildren = new HashMap<>();
Map<String, List<String>> schemaAttrNameToParents = new HashMap<>();
Map<String, List<String>> schemaAttrNameToChildren = new TreeMap<>();
Map<String, List<String>> schemaAttrNameToParents = new TreeMap<>();
elementNameToElement.entrySet().stream().forEach((entry) -> {
String key = "nsa-" + entry.getKey();
if (this.ignoredIds.contains(key)) {
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 8400b84

Please sign in to comment.