From 6b8c6d515224317ec0942d286c94076e603c933c Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Tue, 14 Apr 2020 22:24:25 +0200 Subject: [PATCH 1/3] Update plugins and dependencies - maven-assembly-plugin 3.0.0 -> 3.2.0 (bogus warning) - assert 2.9.0 -> 3.15.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6d6668f1..2dce7fd3 100644 --- a/pom.xml +++ b/pom.xml @@ -335,7 +335,7 @@ maven-assembly-plugin - 3.0.0 + 3.2.0 false @@ -505,7 +505,7 @@ org.assertj assertj-core - 2.9.0 + 3.15.0 net.bytebuddy From a470d90d2fc45f6edee3170e5fac8af7a9117cab Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Tue, 14 Apr 2020 22:27:42 +0200 Subject: [PATCH 2/3] AssertJ Unittests run on other locales - Some Tests expect Messages in english, and running them on other locales won't work. So the test-classes set the locale to english before the tests and restore them after the tests --- .../org/xmlunit/assertj/LocaleModifier.java | 16 ++++++++++++++ .../org/xmlunit/assertj/ValueAssertTest.java | 21 +++++++++++++++---- .../assertj/XmlAssertValidationTest.java | 20 +++++++++++++++--- .../assertj/XmlAssertValueByXPathTest.java | 14 +++++++++++++ 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 xmlunit-assertj/src/test/java/org/xmlunit/assertj/LocaleModifier.java diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/LocaleModifier.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/LocaleModifier.java new file mode 100644 index 00000000..e9958058 --- /dev/null +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/LocaleModifier.java @@ -0,0 +1,16 @@ +package org.xmlunit.assertj; + +import java.util.Locale; + +public class LocaleModifier { + private Locale locale; + + public void setEnglish() { + locale = Locale.getDefault(); + Locale.setDefault(new Locale("en")); + } + + public void restore() { + Locale.setDefault(locale); + } +} diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java index d1db6bd9..af05190f 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java @@ -13,19 +13,20 @@ */ package org.xmlunit.assertj; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.mockito.Mockito; import org.w3c.dom.Element; import org.xml.sax.InputSource; -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPathFactory; +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; import static org.xmlunit.assertj.ExpectedException.none; import static org.xmlunit.assertj.XmlAssert.assertThat; @@ -34,6 +35,18 @@ public class ValueAssertTest { @Rule public ExpectedException thrown = none(); + private static LocaleModifier locale = new LocaleModifier(); + + @BeforeClass + public static void overwriteLocale() { + locale.setEnglish(); + } + + @AfterClass + public static void restoreLocale() { + locale.restore(); + } + @Test public void testAsInt_shouldPass() { diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java index cefecf36..72bef462 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java @@ -13,15 +13,16 @@ */ package org.xmlunit.assertj; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.xmlunit.validation.Languages; -import java.io.File; - import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import java.io.File; import static org.xmlunit.assertj.ExpectedException.none; import static org.xmlunit.assertj.XmlAssert.assertThat; @@ -31,6 +32,18 @@ public class XmlAssertValidationTest { @Rule public ExpectedException thrown = none(); + private static LocaleModifier locale = new LocaleModifier(); + + @BeforeClass + public static void overwriteLocale() { + locale.setEnglish(); + } + + @AfterClass + public static void restoreLocale() { + locale.restore(); + } + @Test public void testIsValidAgainst_shouldPass() { StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml")); @@ -89,7 +102,8 @@ public void testIsValidAgainst_withEmptySourcesArray_shouldPass() { StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml")); assertThat(xml).isValidAgainst(); - assertThat(xml).isValidAgainst(new Object[0]); + final Object[] emptyArray = new Object[0]; + assertThat(xml).isValidAgainst(emptyArray); } @Test 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 4aaf96b8..273dcdab 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValueByXPathTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValueByXPathTest.java @@ -13,6 +13,8 @@ */ package org.xmlunit.assertj; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -25,6 +27,18 @@ public class XmlAssertValueByXPathTest { @Rule public ExpectedException thrown = none(); + private static LocaleModifier locale = new LocaleModifier(); + + @BeforeClass + public static void overwriteLocale() { + locale.setEnglish(); + } + + @AfterClass + public static void restoreLocale() { + locale.restore(); + } + @Test public void testValueByXPath_withNull_shouldFailed() { From f5f77fd1fa0f2976b9cdfc81d042f793e6447f5e Mon Sep 17 00:00:00 2001 From: Claudio Clemens Date: Tue, 14 Apr 2020 22:42:23 +0200 Subject: [PATCH 3/3] Import Order corrected - as original code --- .../src/test/java/org/xmlunit/assertj/ValueAssertTest.java | 7 ++++--- .../java/org/xmlunit/assertj/XmlAssertValidationTest.java | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java index af05190f..7869041f 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/ValueAssertTest.java @@ -21,13 +21,14 @@ import org.w3c.dom.Element; import org.xml.sax.InputSource; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPathFactory; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import java.util.HashMap; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPathFactory; + import static org.xmlunit.assertj.ExpectedException.none; import static org.xmlunit.assertj.XmlAssert.assertThat; diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java index 72bef462..a8680f99 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/XmlAssertValidationTest.java @@ -19,10 +19,11 @@ import org.junit.Test; import org.xmlunit.validation.Languages; +import java.io.File; + import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; -import java.io.File; import static org.xmlunit.assertj.ExpectedException.none; import static org.xmlunit.assertj.XmlAssert.assertThat;