Skip to content

Commit 91791c1

Browse files
Boiarshinovsbrannen
authored andcommitted
Fail with full description for XML diff in XmlExpectationsHelper
Closes gh-33827
1 parent dd92eac commit 91791c1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public boolean hasDifferences() {
110110

111111
@Override
112112
public String toString() {
113-
return this.diff.toString();
113+
return this.diff.fullDescription();
114114
}
115115

116116
}

spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java

+11
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,15 @@ void assertXmlEqualExceptionForLessEntries() {
7474
.withMessageContaining("Expected child nodelist length '3' but was '2'");
7575
}
7676

77+
@Test
78+
void assertXmlEqualExceptionWithFullDescription() {
79+
String control = "<root><field1>f1</field1><field2>f2</field2></root>";
80+
String test = "<root><field2>f2</field2><field3>f3</field3></root>";
81+
XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper();
82+
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
83+
xmlHelper.assertXmlEqual(control, test))
84+
.withMessageContaining("Expected child 'field1' but was 'null'")
85+
.withMessageContaining("Expected child 'null' but was 'field3'");
86+
}
87+
7788
}

0 commit comments

Comments
 (0)