From 91791c17568c30eb95bc48138a1679f3b747dee8 Mon Sep 17 00:00:00 2001 From: boiarshinov Date: Thu, 31 Oct 2024 13:44:39 +0300 Subject: [PATCH] Fail with full description for XML diff in XmlExpectationsHelper Closes gh-33827 --- .../test/util/XmlExpectationsHelper.java | 2 +- .../test/util/XmlExpectationsHelperTests.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java index 255d307fd8..69a210c95d 100644 --- a/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java @@ -110,7 +110,7 @@ public class XmlExpectationsHelper { @Override public String toString() { - return this.diff.toString(); + return this.diff.fullDescription(); } } diff --git a/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java index eae8b99b2d..6e855b37f6 100644 --- a/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java @@ -74,4 +74,15 @@ class XmlExpectationsHelperTests { .withMessageContaining("Expected child nodelist length '3' but was '2'"); } + @Test + void assertXmlEqualExceptionWithFullDescription() { + String control = "f1f2"; + String test = "f2f3"; + XmlExpectationsHelper xmlHelper = new XmlExpectationsHelper(); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> + xmlHelper.assertXmlEqual(control, test)) + .withMessageContaining("Expected child 'field1' but was 'null'") + .withMessageContaining("Expected child 'null' but was 'field3'"); + } + }