You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2023/12/16 17:01:49 UTC
(sis) 04/05: Partial port of a few tests to JUnit 5.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 6fa42344446e8b306a1e40ca3661970d07080604
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sat Dec 16 15:37:01 2023 +0100
Partial port of a few tests to JUnit 5.
---
.../sis/xml/CharSequenceSubstitutionTest.java | 19 ++---
.../test/org/apache/sis/xml/LegacyCodesTest.java | 98 ++++++++++++----------
.../org/apache/sis/xml/MarshallerPoolTest.java | 2 +-
.../test/org/apache/sis/xml/NamespacesTest.java | 15 ++--
.../apache/sis/xml/NilReasonMarshallingTest.java | 41 +++++----
.../test/org/apache/sis/xml/TransformerTest.java | 28 +++----
.../apache/sis/xml/TransformingNamespacesTest.java | 4 +-
.../org/apache/sis/xml/UUIDMarshallingTest.java | 35 ++++----
.../org/apache/sis/xml/ValueConverterTest.java | 2 +-
.../org/apache/sis/xml/XLinkMarshallingTest.java | 9 +-
.../test/org/apache/sis/xml/XLinkTest.java | 96 ++++++++++-----------
.../test/org/apache/sis/xml/XPointerTest.java | 2 +-
12 files changed, 177 insertions(+), 174 deletions(-)
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/CharSequenceSubstitutionTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/CharSequenceSubstitutionTest.java
index e2b6c8b679..9fb08ea251 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/CharSequenceSubstitutionTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/CharSequenceSubstitutionTest.java
@@ -29,8 +29,7 @@ import static org.apache.sis.metadata.internal.ImplementationHelper.ISO_NAMESPAC
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.opengis.test.Assert.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.xml.test.TestCase;
import static org.apache.sis.metadata.Assertions.assertXmlEquals;
@@ -81,8 +80,8 @@ public final class CharSequenceSubstitutionTest extends TestCase {
final ReferenceSystemMetadata md = unmarshal(ReferenceSystemMetadata.class, expected);
final Identifier id = md.getName();
- assertEquals("codespace", "L101", id.getCodeSpace());
- assertEquals("code", "EPSG:4326", id.getCode());
+ assertEquals("L101", id.getCodeSpace(), "codespace");
+ assertEquals("EPSG:4326", id.getCode(), "code");
}
/**
@@ -108,8 +107,8 @@ public final class CharSequenceSubstitutionTest extends TestCase {
"</mcc:MD_Identifier>";
final Identifier id = unmarshal(Identifier.class, expected);
- assertEquals("codespace", "L101", id.getCodeSpace());
- assertEquals("code", "EPSG:4326", id.getCode());
+ assertEquals("L101", id.getCodeSpace(), "codespace");
+ assertEquals("EPSG:4326", id.getCode(), "code");
}
/**
@@ -176,8 +175,8 @@ public final class CharSequenceSubstitutionTest extends TestCase {
"</mri:MD_DataIdentification>";
final DataIdentification id = unmarshal(DataIdentification.class, expected);
- assertEquals("purpose", "Investigation", String.valueOf(id.getPurpose()));
- assertSame("purpose", InitiativeType.INVESTIGATION, Types.forCodeTitle(id.getPurpose()));
+ assertEquals("Investigation", String.valueOf(id.getPurpose()), "purpose");
+ assertSame(InitiativeType.INVESTIGATION, Types.forCodeTitle(id.getPurpose()), "purpose");
final String actual = marshal(id);
assertXmlEquals(expected, actual, "xmlns:*");
@@ -202,7 +201,7 @@ public final class CharSequenceSubstitutionTest extends TestCase {
"</gmi:MI_Instrument>";
final Instrument instrument = unmarshal(Instrument.class, expected);
- assertEquals("type", "RADIOMETER", String.valueOf(instrument.getType()));
- assertInstanceOf("type", SensorType.class, Types.forCodeTitle(instrument.getType()));
+ assertEquals("RADIOMETER", String.valueOf(instrument.getType()), "type");
+ assertInstanceOf(SensorType.class, Types.forCodeTitle(instrument.getType()), "type");
}
}
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/LegacyCodesTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/LegacyCodesTest.java
index 50a9a5d178..50af0189e1 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/LegacyCodesTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/LegacyCodesTest.java
@@ -16,11 +16,9 @@
*/
package org.apache.sis.xml;
-import static org.apache.sis.xml.LegacyCodes.*;
-
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
@@ -36,21 +34,35 @@ public final class LegacyCodesTest extends TestCase {
public LegacyCodesTest() {
}
+ /**
+ * Tests {@link LegacyCodes#fromIANA(String)} with the given value.
+ */
+ private static void testFromIANA(final String expected, final String name) {
+ assertEquals(expected, LegacyCodes.fromIANA(name), name);
+ }
+
/**
* Tests {@link LegacyCodes#fromIANA(String)}.
*/
@Test
public void testFromIANA() {
- assertEquals("UTF-8", "utf8", fromIANA("UTF-8"));
- assertEquals("UTF-16", "utf16", fromIANA("UTF-16"));
- assertEquals("ISO-8859-1", "8859part1", fromIANA("ISO-8859-1"));
- assertEquals("JIS_X0201", "jis", fromIANA("JIS_X0201"));
- assertEquals("Shift_JIS", "shiftJIS", fromIANA("Shift_JIS"));
+ testFromIANA("utf8", "UTF-8");
+ testFromIANA("utf16", "UTF-16");
+ testFromIANA("8859part1", "ISO-8859-1");
+ testFromIANA("jis", "JIS_X0201");
+ testFromIANA("shiftJIS", "Shift_JIS");
// Test non-standard cases.
- assertEquals("utf-8", "utf8", fromIANA("utf-8"));
- assertEquals("shift_jis", "shiftJIS", fromIANA("shift_jis"));
- assertEquals("SHIFT_JIS", "shiftJIS", fromIANA("SHIFT_JIS"));
+ testFromIANA("utf8", "utf-8");
+ testFromIANA("shiftJIS", "shift_jis");
+ testFromIANA("shiftJIS", "SHIFT_JIS");
+ }
+
+ /**
+ * Tests {@link LegacyCodes#toIANA(String)} with the given value.
+ */
+ private static void testToIANA(final String expected, final String name) {
+ assertEquals(expected, LegacyCodes.toIANA(name), name);
}
/**
@@ -58,39 +70,39 @@ public final class LegacyCodesTest extends TestCase {
*/
@Test
public void testToIANA() {
- assertEquals("ucs2", "UCS-2", toIANA("ucs2"));
- assertEquals("ucs4", "UCS-4", toIANA("ucs4"));
- assertEquals("utf7", "UTF-7", toIANA("utf7"));
- assertEquals("utf8", "UTF-8", toIANA("utf8"));
- assertEquals("utf16", "UTF-16", toIANA("utf16"));
- assertEquals("8859part1", "ISO-8859-1", toIANA("8859part1"));
- assertEquals("8859part2", "ISO-8859-2", toIANA("8859part2"));
- assertEquals("8859part3", "ISO-8859-3", toIANA("8859part3"));
- assertEquals("8859part4", "ISO-8859-4", toIANA("8859part4"));
- assertEquals("8859part5", "ISO-8859-5", toIANA("8859part5"));
- assertEquals("8859part6", "ISO-8859-6", toIANA("8859part6"));
- assertEquals("8859part7", "ISO-8859-7", toIANA("8859part7"));
- assertEquals("8859part8", "ISO-8859-8", toIANA("8859part8"));
- assertEquals("8859part9", "ISO-8859-9", toIANA("8859part9"));
- assertEquals("8859part10", "ISO-8859-10", toIANA("8859part10"));
- assertEquals("8859part11", "ISO-8859-11", toIANA("8859part11"));
- assertEquals("8859part12", "ISO-8859-12", toIANA("8859part12"));
- assertEquals("8859part13", "ISO-8859-13", toIANA("8859part13"));
- assertEquals("8859part14", "ISO-8859-14", toIANA("8859part14"));
- assertEquals("8859part15", "ISO-8859-15", toIANA("8859part15"));
- assertEquals("8859part16", "ISO-8859-16", toIANA("8859part16"));
- assertEquals("jis", "JIS_X0201", toIANA("jis"));
- assertEquals("shiftJIS", "Shift_JIS", toIANA("shiftJIS"));
- assertEquals("eucJP", "EUC-JP", toIANA("eucJP"));
- assertEquals("usAscii", "US-ASCII", toIANA("usAscii"));
- assertEquals("ebcdic", "EBCDIC", toIANA("ebcdic"));
- assertEquals("eucKR", "EUC-KR", toIANA("eucKR"));
- assertEquals("big5", "Big5", toIANA("big5"));
- assertEquals("GB2312", "GB2312", toIANA("GB2312"));
+ testToIANA("UCS-2", "ucs2");
+ testToIANA("UCS-4", "ucs4");
+ testToIANA("UTF-7", "utf7");
+ testToIANA("UTF-8", "utf8");
+ testToIANA("UTF-16", "utf16");
+ testToIANA("ISO-8859-1", "8859part1");
+ testToIANA("ISO-8859-2", "8859part2");
+ testToIANA("ISO-8859-3", "8859part3");
+ testToIANA("ISO-8859-4", "8859part4");
+ testToIANA("ISO-8859-5", "8859part5");
+ testToIANA("ISO-8859-6", "8859part6");
+ testToIANA("ISO-8859-7", "8859part7");
+ testToIANA("ISO-8859-8", "8859part8");
+ testToIANA("ISO-8859-9", "8859part9");
+ testToIANA("ISO-8859-10", "8859part10");
+ testToIANA("ISO-8859-11", "8859part11");
+ testToIANA("ISO-8859-12", "8859part12");
+ testToIANA("ISO-8859-13", "8859part13");
+ testToIANA("ISO-8859-14", "8859part14");
+ testToIANA("ISO-8859-15", "8859part15");
+ testToIANA("ISO-8859-16", "8859part16");
+ testToIANA("JIS_X0201", "jis");
+ testToIANA("Shift_JIS", "shiftJIS");
+ testToIANA("EUC-JP", "eucJP");
+ testToIANA("US-ASCII", "usAscii");
+ testToIANA("EBCDIC", "ebcdic");
+ testToIANA("EUC-KR", "eucKR");
+ testToIANA("Big5", "big5");
+ testToIANA("GB2312", "GB2312");
// Test non-standard cases.
- assertEquals("UCS2", "UCS-2", toIANA("UCS2"));
- assertEquals("euckr", "EUC-KR", toIANA("euckr"));
- assertEquals("EUCKR", "EUC-KR", toIANA("EUCKR"));
+ testToIANA("UCS-2", "UCS2");
+ testToIANA("EUC-KR", "euckr");
+ testToIANA("EUC-KR", "EUCKR");
}
}
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/MarshallerPoolTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/MarshallerPoolTest.java
index c3be2d21ef..5acca4af58 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/MarshallerPoolTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/MarshallerPoolTest.java
@@ -22,7 +22,7 @@ import jakarta.xml.bind.JAXBException;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NamespacesTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NamespacesTest.java
index 72d6ed328d..6c87d0e100 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NamespacesTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NamespacesTest.java
@@ -20,7 +20,7 @@ import static org.apache.sis.metadata.internal.ImplementationHelper.ISO_NAMESPAC
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
@@ -55,11 +55,12 @@ public final class NamespacesTest extends TestCase {
*/
@Test
public void testGuessForType() {
- assertSame("CI_Citation", Namespaces.CIT, Namespaces.guessForType("CI_Citation"));
- assertSame("EX_Extent", Namespaces.GEX, Namespaces.guessForType("EX_Extent"));
- assertSame("MD_Metadata", Namespaces.MDB, Namespaces.guessForType("MD_Metadata"));
- assertSame("MD_DataIdentification", Namespaces.MRI, Namespaces.guessForType("MD_DataIdentification"));
- assertSame("DS_InitiativeTypeCode", Namespaces.MRI, Namespaces.guessForType("DS_InitiativeTypeCode"));
- assertSame("DCPList", Namespaces.SRV, Namespaces.guessForType("DCPList"));
+ String type;
+ assertSame(Namespaces.CIT, Namespaces.guessForType(type = "CI_Citation"), type);
+ assertSame(Namespaces.GEX, Namespaces.guessForType(type = "EX_Extent"), type);
+ assertSame(Namespaces.MDB, Namespaces.guessForType(type = "MD_Metadata"), type);
+ assertSame(Namespaces.MRI, Namespaces.guessForType(type = "MD_DataIdentification"), type);
+ assertSame(Namespaces.MRI, Namespaces.guessForType(type = "DS_InitiativeTypeCode"), type);
+ assertSame(Namespaces.SRV, Namespaces.guessForType(type = "DCPList"), type);
}
}
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NilReasonMarshallingTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NilReasonMarshallingTest.java
index 3e1e1df866..bc37a211ed 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NilReasonMarshallingTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/NilReasonMarshallingTest.java
@@ -23,8 +23,7 @@ import org.opengis.metadata.citation.Citation;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.opengis.test.Assert.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.xml.test.TestCase;
import static org.apache.sis.metadata.Assertions.assertTitleEquals;
@@ -63,15 +62,15 @@ public final class NilReasonMarshallingTest extends TestCase {
assertTitleEquals("citation", "A title", citation);
final Series series = citation.getSeries();
- assertInstanceOf("Should have instantiated a proxy.", NilObject.class, series);
+ assertInstanceOf(NilObject.class, series, "Should have instantiated a proxy.");
final NilReason reason = ((NilObject) series).getNilReason();
- assertSame("nilReason", NilReason.MISSING, reason);
- assertNull("NilReason.explanation", reason.getOtherExplanation());
- assertNull("NilReason.URI", reason.getURI());
+ assertSame(NilReason.MISSING, reason, "nilReason");
+ assertNull(reason.getOtherExplanation(), "NilReason.explanation");
+ assertNull(reason.getURI(), "NilReason.URI");
assertEquals("Series[missing]", series.toString());
- assertNull("All attributes are expected to be null.", series.getName());
+ assertNull(series.getName(), "All attributes are expected to be null.");
final String actual = marshal(citation);
assertXmlEquals(expected, actual, "xmlns:*");
@@ -98,14 +97,14 @@ public final class NilReasonMarshallingTest extends TestCase {
final Band result = unmarshal(Band.class, expected);
final Double minValue = result.getMinValue();
- assertNotNull("Expected a sentinel value.", minValue);
- assertTrue("Nil value shall be NaN.", minValue.isNaN());
- assertSame("nilReason", NilReason.UNKNOWN, NilReason.forObject(minValue));
+ assertNotNull(minValue, "Expected a sentinel value.");
+ assertTrue(minValue.isNaN(), "Nil value shall be NaN.");
+ assertSame(NilReason.UNKNOWN, NilReason.forObject(minValue), "nilReason");
final Double peakResponse = result.getMinValue();
- assertNotNull("Expected a sentinel value.", peakResponse);
- assertTrue("Nil value shall be NaN.", peakResponse.isNaN());
- assertSame("nilReason", NilReason.UNKNOWN, NilReason.forObject(peakResponse));
+ assertNotNull(peakResponse, "Expected a sentinel value.");
+ assertTrue(peakResponse.isNaN(), "Nil value shall be NaN.");
+ assertSame(NilReason.UNKNOWN, NilReason.forObject(peakResponse), "nilReason");
final String actual = marshal(result);
assertXmlEquals(expected, actual, "xmlns:*");
@@ -133,14 +132,14 @@ public final class NilReasonMarshallingTest extends TestCase {
assertTitleEquals("citation", "A title", citation);
final Series series = citation.getSeries();
- assertInstanceOf("Should have instantiated a proxy.", NilObject.class, series);
+ assertInstanceOf(NilObject.class, series, "Should have instantiated a proxy.");
final NilReason reason = ((NilObject) series).getNilReason();
- assertEquals("NilReason.explanation", "myReason", reason.getOtherExplanation());
- assertNull("NilReason.URI", reason.getURI());
+ assertEquals("myReason", reason.getOtherExplanation(), "NilReason.explanation");
+ assertNull(reason.getURI(), "NilReason.URI");
assertEquals("Series[other:myReason]", series.toString());
- assertNull("All attributes are expected to be null.", series.getName());
+ assertNull(series.getName(), "All attributes are expected to be null.");
final String actual = marshal(citation);
assertXmlEquals(expected, actual, "xmlns:*");
@@ -168,14 +167,14 @@ public final class NilReasonMarshallingTest extends TestCase {
assertTitleEquals("citation", "A title", citation);
final Series series = citation.getSeries();
- assertInstanceOf("Should have instantiated a proxy.", NilObject.class, series);
+ assertInstanceOf(NilObject.class, series, "Should have instantiated a proxy.");
final NilReason reason = ((NilObject) series).getNilReason();
- assertNull("NilReason.explanation", reason.getOtherExplanation());
- assertEquals("NilReason.URI", "http://www.myreason.org", String.valueOf(reason.getURI()));
+ assertNull(reason.getOtherExplanation(), "NilReason.explanation");
+ assertEquals("http://www.myreason.org", String.valueOf(reason.getURI()), "NilReason.URI");
assertEquals("Series[http://www.myreason.org]", series.toString());
- assertNull("All attributes are expected to be null.", series.getName());
+ assertNull(series.getName(), "All attributes are expected to be null.");
final String actual = marshal(citation);
assertXmlEquals(expected, actual, "xmlns:*");
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformerTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformerTest.java
index 85c5137040..3671e6b820 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformerTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformerTest.java
@@ -23,7 +23,7 @@ import org.apache.sis.xml.util.LegacyNamespaces;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
@@ -46,22 +46,22 @@ public final class TransformerTest extends TestCase {
public void testLoad() {
final Set<String> targets = new HashSet<>(12);
final Map<String, Map<String,String>> namespaces = Transformer.load(false, TransformingReader.FILENAME, targets, 260);
- assertTrue(LegacyNamespaces.GMI_ALIAS, targets.contains(LegacyNamespaces.GMI_ALIAS));
- assertTrue(LegacyNamespaces.GMI, targets.contains(LegacyNamespaces.GMI));
- assertTrue(LegacyNamespaces.GMD, targets.contains(LegacyNamespaces.GMD));
- assertTrue(LegacyNamespaces.SRV, targets.contains(LegacyNamespaces.SRV));
- assertTrue(LegacyNamespaces.GCO, targets.contains(LegacyNamespaces.GCO));
- assertTrue(LegacyNamespaces.GMX, targets.contains(LegacyNamespaces.GMX));
- assertTrue(LegacyNamespaces.GML, targets.contains(LegacyNamespaces.GML));
+ assertTrue(targets.contains(LegacyNamespaces.GMI_ALIAS), LegacyNamespaces.GMI_ALIAS);
+ assertTrue(targets.contains(LegacyNamespaces.GMI), LegacyNamespaces.GMI );
+ assertTrue(targets.contains(LegacyNamespaces.GMD), LegacyNamespaces.GMD );
+ assertTrue(targets.contains(LegacyNamespaces.SRV), LegacyNamespaces.SRV );
+ assertTrue(targets.contains(LegacyNamespaces.GCO), LegacyNamespaces.GCO );
+ assertTrue(targets.contains(LegacyNamespaces.GMX), LegacyNamespaces.GMX );
+ assertTrue(targets.contains(LegacyNamespaces.GML), LegacyNamespaces.GML );
Map<String, String> m = namespaces.get("CI_Citation");
- assertNotNull("CI_Citation", m);
- assertEquals("title", Namespaces.CIT, m.get("title"));
- assertEquals("edition", Namespaces.CIT, m.get("edition"));
+ assertNotNull(m, "CI_Citation");
+ assertEquals(Namespaces.CIT, m.get("title"), "title");
+ assertEquals(Namespaces.CIT, m.get("edition"), "edition");
m = namespaces.get("MD_Metadata");
- assertNotNull("MD_Metadata", m);
- assertEquals("identificationInfo", Namespaces.MDB, m.get("identificationInfo"));
- assertEquals("spatialRepresentationInfo", Namespaces.MDB, m.get("spatialRepresentationInfo"));
+ assertNotNull(m, "MD_Metadata");
+ assertEquals(Namespaces.MDB, m.get("identificationInfo"), "identificationInfo");
+ assertEquals(Namespaces.MDB, m.get("spatialRepresentationInfo"), "spatialRepresentationInfo");
}
}
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformingNamespacesTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformingNamespacesTest.java
index 80fb36e20d..1337bb5adb 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformingNamespacesTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/TransformingNamespacesTest.java
@@ -26,7 +26,7 @@ import org.apache.sis.xml.util.LegacyNamespaces;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
import static org.apache.sis.test.Assertions.assertSetEquals;
@@ -109,7 +109,7 @@ public final class TransformingNamespacesTest extends TestCase implements Namesp
*/
assertNull(getPrefix(LegacyNamespaces.GMD)); // This test is useless if this is non-null.
final String prefix = fns.getPrefix(LegacyNamespaces.GMD);
- assertTrue(prefix, prefixes().contains(prefix));
+ assertTrue(prefixes().contains(prefix), prefix);
}
/**
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/UUIDMarshallingTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/UUIDMarshallingTest.java
index fca4d51cb9..15ac3ddaac 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/UUIDMarshallingTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/UUIDMarshallingTest.java
@@ -23,8 +23,7 @@ import org.opengis.metadata.citation.Citation;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.opengis.test.Assert.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.xml.test.TestCase;
@@ -133,11 +132,11 @@ public final class UUIDMarshallingTest extends TestCase {
* which is the main object of interest in this test.
*/
final Series series = citation.getSeries();
- assertFalse("Unexpected proxy", Proxy.isProxyClass(series.getClass()));
- assertInstanceOf("Expected IdentifiedObject", IdentifiedObject.class, series);
+ assertFalse(Proxy.isProxyClass(series.getClass()), "Citation.series.isProxy");
+ assertInstanceOf(IdentifiedObject.class, series, "Citation.series");
final IdentifierMap map = ((IdentifiedObject) series).getIdentifierMap();
- assertEquals("series", "My aggregate dataset", series.getName().toString());
- assertNull ("href", map.get(IdentifierSpace.HREF));
+ assertEquals("My aggregate dataset", series.getName().toString(), "series");
+ assertNull(map.get(IdentifierSpace.HREF), "href");
assertEquals(UUID_VALUE, String.valueOf(map.get(IdentifierSpace.UUID)));
/*
* Marshal the object back to XML and compare with the original string
@@ -184,12 +183,12 @@ public final class UUIDMarshallingTest extends TestCase {
* which is the main object of interest in this test.
*/
final Series series = citation.getSeries();
- assertInstanceOf("Citation.series", IdentifiedObject.class, series);
- assertFalse ("Citation.series.isProxy", Proxy.isProxyClass(series.getClass()));
- assertEquals ("Citation.series.name", "My aggregate dataset", series.getName().toString());
+ assertInstanceOf(IdentifiedObject.class, series, "Citation.series");
+ assertFalse(Proxy.isProxyClass(series.getClass()), "Citation.series.isProxy");
+ assertEquals("My aggregate dataset", series.getName().toString(), "Citation.series.name");
final IdentifierMap map = ((IdentifiedObject) series).getIdentifierMap();
- assertNull ("href", map.get(IdentifierSpace.HREF));
- assertEquals("uuid", UUID_VALUE, map.get(IdentifierSpace.UUID));
+ assertNull(map.get(IdentifierSpace.HREF), "href");
+ assertEquals(UUID_VALUE, map.get(IdentifierSpace.UUID), "uuid");
/*
* Marshal the object back to XML and compare with the expected result. The result shall be
* slightly different than the original XML, since the UUID in the <cit:series> element shall
@@ -217,14 +216,14 @@ public final class UUIDMarshallingTest extends TestCase {
* which is the main object of interest in this test.
*/
final Series series = citation.getSeries();
- assertInstanceOf("Citation.series", IdentifiedObject.class, series);
- assertNull ("Citation.series.name", series.getName());
- assertTrue ("Citation.series.isProxy", Proxy.isProxyClass(series.getClass()));
- assertInstanceOf("Citation.series", NilObject.class, series);
- assertEquals ("Series[{gco:uuid=“" + UUID_VALUE + "”}]", series.toString());
+ assertInstanceOf(IdentifiedObject.class, series, "Citation.series");
+ assertNull(series.getName(), "Citation.series.name");
+ assertTrue(Proxy.isProxyClass(series.getClass()), "Citation.series.isProxy");
+ assertInstanceOf(NilObject.class, series, "Citation.series");
+ assertEquals("Series[{gco:uuid=“" + UUID_VALUE + "”}]", series.toString());
final IdentifierMap map = ((IdentifiedObject) series).getIdentifierMap();
- assertNull ("href", map.get(IdentifierSpace.HREF));
- assertEquals("uuid", UUID_VALUE, map.get(IdentifierSpace.UUID));
+ assertNull(map.get(IdentifierSpace.HREF), "href");
+ assertEquals(UUID_VALUE, map.get(IdentifierSpace.UUID), "uuid");
/*
* Marshal the object back to XML and compare with the expected result.
*/
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ValueConverterTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ValueConverterTest.java
index d668a303e5..bdcb139b8b 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ValueConverterTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/ValueConverterTest.java
@@ -24,7 +24,7 @@ import static org.apache.sis.measure.Units.RADIAN;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java
index 36677fa31d..8101c976a4 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkMarshallingTest.java
@@ -28,8 +28,7 @@ import org.apache.sis.util.ComparisonMode;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.opengis.test.Assert.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.DependsOn;
import org.apache.sis.xml.test.TestCase;
import static org.apache.sis.metadata.Assertions.assertXmlEquals;
@@ -77,10 +76,10 @@ public final class XLinkMarshallingTest extends TestCase {
*/
private static void verify(final boolean isNilExpected, final DefaultMetadata metadata) {
final Identification identification = getSingleton(metadata.getIdentificationInfo());
- assertEquals("NilObject", isNilExpected, identification instanceof NilObject);
- assertInstanceOf("Identification", IdentifiedObject.class, identification);
+ assertEquals(isNilExpected, identification instanceof NilObject, "NilObject");
+ assertInstanceOf(IdentifiedObject.class, identification, "Identification");
final XLink xlink = ((IdentifiedObject) identification).getIdentifierMap().getSpecialized(IdentifierSpace.XLINK);
- assertEquals("xlink:href", "http://test.net", xlink.getHRef().toString());
+ assertEquals("http://test.net", xlink.getHRef().toString(), "xlink:href");
}
/**
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java
index 6d6193c86f..6ac84d0d41 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XLinkTest.java
@@ -22,7 +22,7 @@ import org.apache.sis.util.SimpleInternationalString;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;
@@ -38,6 +38,20 @@ public final class XLinkTest extends TestCase {
public XLinkTest() {
}
+ /**
+ * Verifies that the hash code is different than the given value.
+ *
+ * @param hashCode the old hash code.
+ * @param link the XLink to hash.
+ * @return the new hash code.
+ */
+ private static int assertHashCodeChanged(int hashCode, final XLink link) {
+ final int newHash = link.hashCode();
+ assertNotEquals(hashCode, newHash, "Hash code should have changed.");
+ assertNotEquals(0, hashCode, "Hash code cannot be zero.");
+ return newHash;
+ }
+
/**
* Tests the automatic {@link XLink#getType()} detection.
*
@@ -53,62 +67,51 @@ public final class XLinkTest extends TestCase {
link.setType(XLink.Type.AUTO);
assertEquals(XLink.Type.TITLE, link.getType());
assertEquals("XLink[type=\"title\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
link.setRole(new URI("org:apache:sis:role"));
assertEquals(XLink.Type.EXTENDED, link.getType());
assertEquals("XLink[type=\"extended\", role=\"org:apache:sis:role\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
link.setTitle(new SimpleInternationalString("Some title"));
assertEquals(XLink.Type.EXTENDED, link.getType());
assertEquals("XLink[type=\"extended\", role=\"org:apache:sis:role\", title=\"Some title\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
link.setLabel("SomeLabel");
assertEquals(XLink.Type.RESOURCE, link.getType());
assertEquals("XLink[type=\"resource\", role=\"org:apache:sis:role\", title=\"Some title\", label=\"SomeLabel\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
link.setHRef(new URI("org:apache:sis:href"));
assertEquals(XLink.Type.LOCATOR, link.getType());
assertEquals("XLink[type=\"locator\", href=\"org:apache:sis:href\", role=\"org:apache:sis:role\", title=\"Some title\", label=\"SomeLabel\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
link.setShow(XLink.Show.NEW);
- assertNull("Cannot be Type.SIMPLE if a label is defined.", link.getType());
+ assertNull(link.getType(), "Cannot be Type.SIMPLE if a label is defined.");
assertEquals("XLink[href=\"org:apache:sis:href\", role=\"org:apache:sis:role\", title=\"Some title\", show=\"new\", label=\"SomeLabel\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
link.setLabel(null);
assertEquals(XLink.Type.SIMPLE, link.getType());
assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\", role=\"org:apache:sis:role\", title=\"Some title\", show=\"new\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
link.setActuate(XLink.Actuate.ON_LOAD);
assertEquals(XLink.Type.SIMPLE, link.getType());
assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\", role=\"org:apache:sis:role\", title=\"Some title\", show=\"new\", actuate=\"onLoad\"]", link.toString());
- assertFalse("Hash code should have changed.", hashCode == (hashCode = link.hashCode()));
- assertFalse("Hash code cannot be zero.", hashCode == 0);
+ hashCode = assertHashCodeChanged(hashCode, link);
/*
* Now freezes the XLink and ensures that it is really immutable.
*/
link.freeze();
- assertEquals("hashCode", hashCode, link.hashCode());
- try {
- link.setType(null);
- fail("The XLink should be unmodifiable.");
- } catch (UnsupportedOperationException e) {
- // This is the expected exception.
- assertTrue(e.getMessage().contains("XLink"));
- }
+ assertEquals(hashCode, link.hashCode(), "hashCode");
+ String message;
+ message = assertThrows(UnsupportedOperationException.class, () -> link.setType(null),
+ "The XLink should be unmodifiable.").getMessage();
+ assertTrue(message.contains("XLink"));
}
/**
@@ -121,41 +124,32 @@ public final class XLinkTest extends TestCase {
final XLink link = new XLink();
link.setType(XLink.Type.SIMPLE);
link.setHRef(new URI("org:apache:sis:href"));
+ String message;
+ /*
+ * Should not be allowed to set the label.
+ */
assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\"]", link.toString());
- try {
- link.setLabel("SomeLabel");
- fail("Should not be allowed to set the label.");
- } catch (IllegalStateException e) {
- // This is the expected exception. The message should contain the type name.
- assertTrue(e.getMessage().contains("label"));
- assertTrue(e.getMessage().contains("simple"));
- }
- assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\"]", link.toString());
- try {
- link.setType(XLink.Type.EXTENDED);
- fail("Should not be allowed to set a type that does not include HREF.");
- } catch (IllegalStateException e) {
- // This is the expected exception. The message should contain the type name.
- assertTrue(e.getMessage().contains("extended"));
- }
+ message = assertThrows(IllegalStateException.class, () -> link.setLabel("SomeLabel")).getMessage();
+ assertTrue(message.contains("label"));
+ assertTrue(message.contains("simple"));
+ /*
+ * Should not be allowed to set a type that does not include HREF.
+ */
assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\"]", link.toString());
+ message = assertThrows(IllegalStateException.class, () -> link.setType(XLink.Type.EXTENDED)).getMessage();
+ assertTrue(message.contains("extended"));
/*
- * The Locator type contains the HREF attribute, so the following operation should be
- * allowed.
+ * The Locator type contains the HREF attribute, so the following operation should be allowed.
*/
+ assertEquals("XLink[type=\"simple\", href=\"org:apache:sis:href\"]", link.toString());
link.setType(XLink.Type.LOCATOR);
assertEquals("XLink[type=\"locator\", href=\"org:apache:sis:href\"]", link.toString());
/*
* Now freezes the XLink and ensures that it is really immutable.
*/
link.freeze();
- try {
- link.setHRef(null);
- fail("The XLink should be unmodifiable.");
- } catch (UnsupportedOperationException e) {
- // This is the expected exception.
- assertTrue(e.getMessage().contains("XLink"));
- }
+ message = assertThrows(UnsupportedOperationException.class, () -> link.setHRef(null)).getMessage();
+ assertTrue(message.contains("XLink"));
}
/**
diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XPointerTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XPointerTest.java
index e2841549bd..f65ac88c16 100644
--- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XPointerTest.java
+++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/XPointerTest.java
@@ -20,7 +20,7 @@ import org.apache.sis.util.Characters;
// Test dependencies
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import org.apache.sis.test.TestCase;