From db2ff6c44a627f191bf53b8cad02a154a402f2b9 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 4 Feb 2021 12:54:22 +0100 Subject: [PATCH] more tests affected by message changes in AssertJ 3.19.0 see #212 --- RELEASE_NOTES.md | 4 ++++ .../org/xmlunit/assertj/XmlAssertNodesByXPathTest.java | 8 ++++---- .../org/xmlunit/assertj/XmlAssertValueByXPathTest.java | 8 ++++---- .../test/java/org/xmlunit/assertj3/ValueAssertTest.java | 9 ++++++++- .../org/xmlunit/assertj3/XmlAssertNodesByXPathTest.java | 8 ++++---- .../org/xmlunit/assertj3/XmlAssertValueByXPathTest.java | 6 +++--- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 57cf0cd1..30e322d1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,10 @@ ## XMLUnit for Java 2.8.3 - /not released, yet/ +* adjusted unit tests so they pass when AssertJ 3.19.0 is used. + [#212](https://github.com/xmlunit/xmlunit/pull/212) by + [mmathesius](https://github.com/mmathesius) + ## XMLUnit for Java 2.8.2 - /Released 2020-12-21/ * `CompareAssert` inside the AssertJ3 module swapped the expected and diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertNodesByXPathTest.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertNodesByXPathTest.java index 6499f67c..de253e69 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertNodesByXPathTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertNodesByXPathTest.java @@ -43,17 +43,17 @@ public void testAssertThat_withNull_shouldFailed() { } @Test - public void testNodesByXPath_withNull_shouldFailed() { + public void testNodesByXPath_withNull_shouldFail() { - thrown.expectAssertionError(format("%nExpecting not blank but was:")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )null>?")); assertThat("").nodesByXPath(null); } @Test - public void testNodesByXPath_withWhitespacesOnly_shouldFailed() { + public void testNodesByXPath_withWhitespacesOnly_shouldFail() { - thrown.expectAssertionError(format("%nExpecting not blank but was:<\" \n \t\">")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )\" \n \t\">?")); assertThat("").nodesByXPath(" \n \t"); } diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValueByXPathTest.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValueByXPathTest.java index 3ce52843..f0125156 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValueByXPathTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValueByXPathTest.java @@ -31,17 +31,17 @@ public class XmlAssertValueByXPathTest { public static SetEnglishLocaleRule locale = new SetEnglishLocaleRule(); @Test - public void testValueByXPath_withNull_shouldFailed() { + public void testValueByXPath_withNull_shouldFail() { - thrown.expectAssertionError(format("%nExpecting not blank but was:")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )null>?")); assertThat("").valueByXPath(null); } @Test - public void testValueByXPath_withWhitespacesOnly_shouldFailed() { + public void testValueByXPath_withWhitespacesOnly_shouldFail() { - thrown.expectAssertionError(format("%nExpecting not blank but was:<\" \n \t\">")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )\" \n \t\">?")); assertThat("").valueByXPath(" \n \t"); } diff --git a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/ValueAssertTest.java b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/ValueAssertTest.java index a4e36e36..92f3aabb 100644 --- a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/ValueAssertTest.java +++ b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/ValueAssertTest.java @@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import java.util.HashMap; +import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -263,7 +264,13 @@ public void testIsEqualTo_withAttributeValueExpression_shouldPass() { @Test public void testIsEqualTo_withAttributeValueExpression_shouldFailed() { - thrown.expectAssertionError("expected:<\"[something]\"> but was:<\"[abc]\">"); + thrown.expectAssertionErrorPattern(".*(" + // AssertJ 3.18.1 + + Pattern.quote("expected:<\"[something]\"> but was:<\"[abc]\">") + + "|" + // AssertJ 3.19.0+ + + Pattern.quote("Expecting:\n <\"abc\">\nto be equal to:\n <\"something\">\nbut was not.") + + ")"); String xml = ""; diff --git a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertNodesByXPathTest.java b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertNodesByXPathTest.java index 166633ee..2f811181 100644 --- a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertNodesByXPathTest.java +++ b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertNodesByXPathTest.java @@ -43,17 +43,17 @@ public void testAssertThat_withNull_shouldFailed() { } @Test - public void testNodesByXPath_withNull_shouldFailed() { + public void testNodesByXPath_withNull_shouldFail() { - thrown.expectAssertionError(format("%nExpecting not blank but was:")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )null>?")); assertThat("").nodesByXPath(null); } @Test - public void testNodesByXPath_withWhitespacesOnly_shouldFailed() { + public void testNodesByXPath_withWhitespacesOnly_shouldFail() { - thrown.expectAssertionError(format("%nExpecting not blank but was:<\" \n \t\">")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )\" \n \t\">?")); assertThat("").nodesByXPath(" \n \t"); } diff --git a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertValueByXPathTest.java b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertValueByXPathTest.java index 7ac9a3f7..0dadcce0 100644 --- a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertValueByXPathTest.java +++ b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/XmlAssertValueByXPathTest.java @@ -31,9 +31,9 @@ public class XmlAssertValueByXPathTest { public static SetEnglishLocaleRule locale = new SetEnglishLocaleRule(); @Test - public void testValueByXPath_withNull_shouldFailed() { + public void testValueByXPath_withNull_shouldFail() { - thrown.expectAssertionError(format("%nExpecting not blank but was:")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )null>?")); assertThat("").valueByXPath(null); } @@ -41,7 +41,7 @@ public void testValueByXPath_withNull_shouldFailed() { @Test public void testValueByXPath_withWhitespacesOnly_shouldFailed() { - thrown.expectAssertionError(format("%nExpecting not blank but was:<\" \n \t\">")); + thrown.expectAssertionErrorPattern(format("%nExpecting not blank but was:(<| )\" \n \t\">?")); assertThat("").valueByXPath(" \n \t"); }