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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new ace1c7aeee Add a JUnit test for URN to temporal CRS. Opportunistically port `CRSTest` to JUnit 5 and related cleaning elsewhere. ace1c7aeee is described below commit ace1c7aeee4ecc65430dd26b3ee8ed7b5e47b0ca Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sun Jan 21 17:22:38 2024 +0100 Add a JUnit test for URN to temporal CRS. Opportunistically port `CRSTest` to JUnit 5 and related cleaning elsewhere. --- .../org/apache/sis/console/CommandRunnerTest.java | 4 +- .../apache/sis/coverage/grid/GridExtentTest.java | 12 +- .../test/org/apache/sis/xml/XLinkTest.java | 6 +- .../test/org/apache/sis/io/wkt/ColorsTest.java | 3 +- .../test/org/apache/sis/io/wkt/ElementTest.java | 6 +- .../sis/io/wkt/GeodeticObjectParserTest.java | 3 +- .../org/apache/sis/io/wkt/WKTDictionaryTest.java | 6 +- .../test/org/apache/sis/io/wkt/WKTFormatTest.java | 3 +- .../test/org/apache/sis/referencing/CRSTest.java | 149 +++++++++------------ .../sis/io/stream/ChannelDataOutputTest.java | 2 +- .../org/apache/sis/storage/FeatureQueryTest.java | 2 +- .../apache/sis/storage/StorageConnectorTest.java | 4 +- .../storage/internal/RewindableLineReaderTest.java | 3 +- 13 files changed, 89 insertions(+), 114 deletions(-) diff --git a/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java b/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java index 3760dea71d..d1247ead9d 100644 --- a/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java +++ b/endorsed/src/org.apache.sis.console/test/org/apache/sis/console/CommandRunnerTest.java @@ -135,7 +135,7 @@ public final class CommandRunnerTest extends TestCase { public void testMissingOptionValue() throws InvalidOptionException { final CommandRunner c = new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, "--brief"); // Should not comply. assertEquals(Option.BRIEF, getSingleton(c.options.keySet())); - InvalidOptionException exception = assertThrows(InvalidOptionException.class, + var exception = assertThrows(InvalidOptionException.class, () -> new Dummy(EnumSet.allOf(Option.class), CommandRunner.TEST, "--brief", "--locale")); assertMessageContains(exception, "locale"); } @@ -147,7 +147,7 @@ public final class CommandRunnerTest extends TestCase { */ @Test public void testUnexpectedOption() throws InvalidOptionException { - InvalidOptionException exception = assertThrows(InvalidOptionException.class, + var exception = assertThrows(InvalidOptionException.class, () -> new Dummy(EnumSet.of(Option.HELP, Option.BRIEF), CommandRunner.TEST, "--brief", "--verbose", "--help")); assertMessageContains(exception, "verbose"); } diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java index 7174890014..67ce666f05 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java @@ -297,8 +297,7 @@ public final class GridExtentTest extends TestCase { assertSame(extent.intersect(domain), extent); final GridExtent disjoint = domain.translate(0, 1000); - DisjointExtentException exception; - exception = assertThrows(DisjointExtentException.class, () -> extent.intersect(disjoint)); + var exception = assertThrows(DisjointExtentException.class, () -> extent.intersect(disjoint)); assertMessageContains(exception); } @@ -326,8 +325,7 @@ public final class GridExtentTest extends TestCase { new DimensionNameType[] {DimensionNameType.COLUMN, DimensionNameType.TRACK, DimensionNameType.TIME}, new long[] {100, 200, 40}, new long[] {500, 800, 50}, false); - IllegalArgumentException exception; - exception = assertThrows(IllegalArgumentException.class, () -> domain.intersect(other)); + var exception = assertThrows(IllegalArgumentException.class, () -> domain.intersect(other)); assertMessageContains(exception); } @@ -371,8 +369,7 @@ public final class GridExtentTest extends TestCase { * change in future SIS version). */ slicePoint.setOrdinate(0, 900); - PointOutsideCoverageException exception; - exception = assertThrows(PointOutsideCoverageException.class, () -> extent.slice(slicePoint, new int[] {1, 2})); + var exception = assertThrows(PointOutsideCoverageException.class, () -> extent.slice(slicePoint, new int[] {1, 2})); assertMessageContains(exception, "(900, 47)"); // See above comment. } @@ -388,8 +385,7 @@ public final class GridExtentTest extends TestCase { assertSubspaceEquals(extent, 0,1,2 ); assertSubspaceEquals(extent, 0,1,2,3); - SubspaceNotSpecifiedException exception; - exception = assertThrows(SubspaceNotSpecifiedException.class, () -> extent.getSubspaceDimensions(1)); + var exception = assertThrows(SubspaceNotSpecifiedException.class, () -> extent.getSubspaceDimensions(1)); assertMessageContains(exception); } 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 f4a38ab4c8..c06709dc47 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 @@ -110,8 +110,7 @@ public final class XLinkTest extends TestCase { link.freeze(); assertEquals(hashCode, link.hashCode(), "hashCode"); - UnsupportedOperationException exception; - exception = assertThrows(UnsupportedOperationException.class, () -> link.setType(null), "The XLink should be unmodifiable."); + var exception = assertThrows(UnsupportedOperationException.class, () -> link.setType(null), "The XLink should be unmodifiable."); assertMessageContains(exception, "XLink"); } @@ -148,8 +147,7 @@ public final class XLinkTest extends TestCase { * Now freezes the XLink and ensures that it is really immutable. */ link.freeze(); - UnsupportedOperationException e; - e = assertThrows(UnsupportedOperationException.class, () -> link.setHRef(null)); + var e = assertThrows(UnsupportedOperationException.class, () -> link.setHRef(null)); assertMessageContains(e, "XLink"); } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java index 37c7974deb..988920f9fc 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ColorsTest.java @@ -66,8 +66,7 @@ public final class ColorsTest extends TestCase { */ @Test public void testImmutability() { - UnsupportedOperationException e; - e = assertThrows(UnsupportedOperationException.class, () -> Colors.DEFAULT.setName(ElementKind.METHOD, "blue")); + var e = assertThrows(UnsupportedOperationException.class, () -> Colors.DEFAULT.setName(ElementKind.METHOD, "blue")); assertMessageContains(e, "Colors"); } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java index 5630062043..13e18e57f2 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ElementTest.java @@ -173,7 +173,7 @@ public final class ElementTest extends TestCase { * Tests error message. */ final Element next = parse("B[6.5]"); - ParseException e = assertThrows(ParseException.class, () -> next.pullInteger("forth")); + var e = assertThrows(ParseException.class, () -> next.pullInteger("forth")); assertEquals("Text “6.5” cannot be parsed as an object of type ‘Integer’.", e.getLocalizedMessage()); } @@ -212,7 +212,7 @@ public final class ElementTest extends TestCase { * Tests error message. */ final Element next = parse("ConformanceResult[falseX]"); - ParseException e = assertThrows(ParseException.class, () -> next.pullBoolean("pass")); + var e = assertThrows(ParseException.class, () -> next.pullBoolean("pass")); assertEquals("Missing a “pass” component in “ConformanceResult”.", e.getLocalizedMessage()); } @@ -243,7 +243,7 @@ public final class ElementTest extends TestCase { @Test public void testClose() throws ParseException { final Element element = parse("A[\"B\", \"C\"]"); - ParseException e = assertThrows(ParseException.class, () -> element.close(null)); + var e = assertThrows(ParseException.class, () -> element.close(null)); assertEquals("Unexpected value “B” in “A” element.", e.getLocalizedMessage()); } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java index 1565b4322c..ad5fc89faa 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java @@ -1184,8 +1184,7 @@ public final class GeodeticObjectParserTest extends TestCase { */ @Test public void testIncompatibleUnits() { - ParseException exception; - exception = assertThrows(ParseException.class, () -> parse(GeographicCRS.class, + var exception = assertThrows(ParseException.class, () -> parse(GeographicCRS.class, "GEOGCS[“NAD83”,\n" + " DATUM[“North American Datum 1983”,\n" + " SPHEROID[“GRS 1980”, 6378137.0, 298.257222]],\n" + diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java index 3825c1730e..874c1b928c 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java @@ -108,8 +108,7 @@ public final class WKTDictionaryTest extends TestCase { /* * Test non-existing CRS. */ - NoSuchAuthorityCodeException exception; - exception = assertThrows(NoSuchAuthorityCodeException.class, () -> factory.createGeographicCRS("84")); + var exception = assertThrows(NoSuchAuthorityCodeException.class, () -> factory.createGeographicCRS("84")); assertMessageContains(exception, "84"); } @@ -379,8 +378,7 @@ public final class WKTDictionaryTest extends TestCase { /* * Test non-existent code. */ - FactoryException exception; - exception = assertThrows(FactoryException.class, () -> factory.createGeographicCRS("21")); + var exception = assertThrows(FactoryException.class, () -> factory.createGeographicCRS("21")); assertMessageContains(exception, "21"); } } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java index b6e942962b..c998e75f7a 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java @@ -447,8 +447,7 @@ public final class WKTFormatTest extends TestCase { /* * Verify that FormattableObject.toWKT() reports that the WKT is invalid. */ - UnformattableObjectException e; - e = assertThrows(UnformattableObjectException.class, () -> pm.toWKT()); + var e = assertThrows(UnformattableObjectException.class, () -> pm.toWKT()); assertMessageContains(e, "$name"); /* * Verify that the WKT is still parseable despite the warning. diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java index ffabdf835a..cd02725598 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java @@ -41,8 +41,7 @@ import org.apache.sis.util.Utilities; import org.junit.After; import org.junit.Rule; 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.LoggingWatcher; import org.apache.sis.test.DependsOnMethod; import org.apache.sis.test.DependsOn; @@ -51,6 +50,7 @@ import org.apache.sis.referencing.cs.HardCodedCS; import org.apache.sis.referencing.crs.HardCodedCRS; import org.apache.sis.referencing.operation.HardCodedConversions; import static org.apache.sis.test.Assertions.assertEqualsIgnoreMetadata; +import static org.apache.sis.test.Assertions.assertMessageContains; /** @@ -90,9 +90,9 @@ public final class CRSTest extends TestCase { */ private static void verifyForCode(final SingleCRS expected, final String code) throws FactoryException { final CoordinateReferenceSystem actual = CRS.forCode(code); - assertTrue(code, Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG)); + assertTrue(Utilities.deepEquals(expected, actual, ComparisonMode.DEBUG), code); if (!EPSGFactoryFallback.FORCE_HARDCODED) { - assertSame(code, expected, actual); + assertSame(expected, actual, code); } } @@ -152,11 +152,14 @@ public final class CRSTest extends TestCase { * Tests {@link CRS#forCode(String)} with temporal CRS codes. * * @throws FactoryException if a CRS cannot be constructed. + * + * @see <a href="https://issues.apache.org/jira/browse/SIS-490">SIS-490</a> */ @Test public void testForTemporalCode() throws FactoryException { verifyForCode(CommonCRS.Temporal.JULIAN.crs(), "OGC:JulianDate"); verifyForCode(CommonCRS.Temporal.UNIX.crs(), "OGC:UnixTime"); + verifyForCode(CommonCRS.Temporal.JULIAN.crs(), "urn:ogc:def:crs:OGC::JulianDate"); verifyForCode(CommonCRS.Temporal.TRUNCATED_JULIAN.crs(), "http://www.opengis.net/gml/srs/crs.xml#TruncatedJulianDate"); } @@ -168,12 +171,8 @@ public final class CRSTest extends TestCase { */ @Test public void testForInvalidCode() throws FactoryException { - try { - CRS.forCode("EPSG:4"); - fail("Should not find EPSG:4"); - } catch (NoSuchAuthorityCodeException e) { - assertEquals("4", e.getAuthorityCode()); - } + var e = assertThrows(NoSuchAuthorityCodeException.class, () -> CRS.forCode("EPSG:4")); + assertEquals("4", e.getAuthorityCode()); } /** @@ -183,7 +182,7 @@ public final class CRSTest extends TestCase { final List<SingleCRS> components = CRS.getSingleComponents(CRS.forCode(code)); final int count = Math.min(components.size(), expected.length); for (int i=0; i<count; i++) { - assertTrue(String.valueOf(i), Utilities.deepEquals(expected[i], components.get(i), ComparisonMode.DEBUG)); + assertTrue(Utilities.deepEquals(expected[i], components.get(i), ComparisonMode.DEBUG), String.valueOf(i)); } assertEquals(expected.length, components.size()); } @@ -219,7 +218,7 @@ public final class CRSTest extends TestCase { "GEOGCS[\"GCS WGS 1984\"," + "DATUM[\"WGS 1984\",SPHEROID[\"WGS 1984\",6378137,298.257223563]]," + "PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]]"); - assertInstanceOf("GEOGCS", DefaultGeographicCRS.class, crs); + assertInstanceOf(DefaultGeographicCRS.class, crs); assertEquals("GCS WGS 1984", crs.getName().getCode()); } @@ -230,15 +229,12 @@ public final class CRSTest extends TestCase { */ @Test public void testFromInvalidWKT() throws FactoryException { - try { - CRS.fromWKT("PROJCS[\"Foo\", GEOGCS[\"Foo\", DATUM[\"Foo\", SPHEROID[\"Sphere\", 6371000, 0]], " + - "UNIT[\"Degree\", 0.0174532925199433]], PROJECTION[\"I do not exist\"], " + - "UNIT[\"MEtre\", 1]]"); - fail("Expected NoSuchIdentifierException"); - } catch (NoSuchIdentifierException e) { - final String message = e.getMessage(); - assertTrue(message, message.contains("I do not exist")); - } + var e = assertThrows(NoSuchIdentifierException.class, () -> + CRS.fromWKT("PROJCS[\"Foo\", GEOGCS[\"Foo\", DATUM[\"Foo\", SPHEROID[\"Sphere\", 6371000, 0]], " + + "UNIT[\"Degree\", 0.0174532925199433]], PROJECTION[\"I do not exist\"], " + + "UNIT[\"MEtre\", 1]]")); + + assertMessageContains(e, "I do not exist"); } /** @@ -271,49 +267,43 @@ public final class CRSTest extends TestCase { final ProjectedCRS[] overlappingCRS = Arrays.copyOf(crs, 3); // Exclude the last CRS only. /* * Test between the 3 overlapping CRS without region of interest. We expect the CRS having a domain - * of validity large enough for all CRS; this is the second CRS created in above 'switch' statement. + * of validity large enough for all CRS; this is the second CRS created in above `switch` statement. */ - assertSame("Expected CRS with widest domain of validity.", crs[1], - CRS.suggestCommonTarget(null, overlappingCRS)); + assertSame(crs[1], CRS.suggestCommonTarget(null, overlappingCRS)); /* * If we specify a smaller region of interest, we should get the CRS having the smallest domain of validity that * cover the ROI. Following lines gradually increase the ROI size and verify that we get CRS for larger domain. */ final DefaultGeographicBoundingBox regionOfInterest = new DefaultGeographicBoundingBox(-1, +1, 2.1, 2.9); - assertSame("Expected best fit for [2.1 … 2.9]°N", crs[2], - CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); + assertSame(crs[2], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); // Best fit for [2.1 … 2.9]°N regionOfInterest.setNorthBoundLatitude(3.1); - assertSame("Expected best fit for [2.1 … 3.1]°N", crs[0], - CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); + assertSame(crs[0], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); // Best fit for [2.1 … 3.1]°N regionOfInterest.setSouthBoundLatitude(1.9); - assertSame("Expected best fit for [1.9 … 3.1]°N", crs[1], - CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); + assertSame(crs[1], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS)); // Best fit for [1.9 … 3.1]°N /* * All above tests returned one of the CRS in the given array. Test now a case where none of those CRS * have a domain of validity wide enough, so suggestCommonTarget(…) need to search among the base CRS. + * We expect a GeodeticCRS since none of the ProjectedCRS have a domain of validity wide enough. */ - assertSame("Expected a GeodeticCRS since none of the ProjectedCRS have a domain of validity wide enough.", - crs[0].getBaseCRS(), CRS.suggestCommonTarget(null, crs)); + assertSame(crs[0].getBaseCRS(), CRS.suggestCommonTarget(null, crs)); /* * With the same domain of validity than above, suggestCommonTarget(…) should not need to fallback on the * base CRS anymore. */ - assertSame("Expected best fit for [1.9 … 3.1]°N", crs[1], - CRS.suggestCommonTarget(regionOfInterest, crs)); - + assertSame(crs[1], CRS.suggestCommonTarget(regionOfInterest, crs)); // Best fit for [1.9 … 3.1]°N final ProjectedCRS utm13N = CommonCRS.WGS84.universal(20, 13); final ProjectedCRS utm42S = CommonCRS.WGS84.universal(-2, 42); - assertSame("CRS suggestion should fallback on common base geographic system when possible.", - CommonCRS.WGS84.geographic(), CRS.suggestCommonTarget(null, utm13N, utm42S)); - - assertNotNull("Disjoint systems should return a geographic suggestion when possible", - CRS.suggestCommonTarget(null, - CommonCRS.WGS84.universal(-7, 19), - CommonCRS.NAD27.universal(20, -101), - CommonCRS.NAD27.universal(18, -20) - ) + + // CRS suggestion should fallback on common base geographic system when possible. + assertSame(CommonCRS.WGS84.geographic(), CRS.suggestCommonTarget(null, utm13N, utm42S)); + + // Disjoint systems should return a geographic suggestion when possible. + assertNotNull(CRS.suggestCommonTarget(null, + CommonCRS.WGS84.universal(-7, 19), + CommonCRS.NAD27.universal(20, -101), + CommonCRS.NAD27.universal(18, -20)) ); } @@ -386,14 +376,14 @@ public final class CRSTest extends TestCase { @Test public void testComponentsOfProjectedCRS() { final ProjectedCRS volumetric = HardCodedConversions.mercator3D(); - assertFalse("isHorizontalCRS", CRS.isHorizontalCRS(volumetric)); - assertNull("getTemporalComponent", CRS.getTemporalComponent(volumetric)); - assertNull("getVerticalComponent", CRS.getVerticalComponent(volumetric, false)); + assertFalse(CRS.isHorizontalCRS(volumetric)); + assertNull(CRS.getTemporalComponent(volumetric)); + assertNull(CRS.getVerticalComponent(volumetric, false)); assertEqualsIgnoreMetadata(HardCodedCRS.ELLIPSOIDAL_HEIGHT, CRS.getVerticalComponent(volumetric, true)); final SingleCRS horizontal = CRS.getHorizontalComponent(volumetric); - assertInstanceOf("getHorizontalComponent", ProjectedCRS.class, horizontal); - assertEquals("dimension", 2, horizontal.getCoordinateSystem().getDimension()); - assertTrue("isHorizontalCRS", CRS.isHorizontalCRS(horizontal)); + assertInstanceOf(ProjectedCRS.class, horizontal); + assertEquals(2, horizontal.getCoordinateSystem().getDimension()); + assertTrue(CRS.isHorizontalCRS(horizontal)); } /** @@ -402,8 +392,8 @@ public final class CRSTest extends TestCase { @Test public void testGetComponentAt() { testGetComponentAt( - null, // Null because our CRS has no component for the 'x' axis alone. - null, // Null because our CRS has no component for the 'y' axis alone. + null, // Null because our CRS has no component for the `x` axis alone. + null, // Null because our CRS has no component for the `y` axis alone. HardCodedCRS.GRAVITY_RELATED_HEIGHT, HardCodedCRS.TIME, HardCodedCRS.WGS84, @@ -414,8 +404,8 @@ public final class CRSTest extends TestCase { * Now test again, but with a more hierarchical structure: ((x,y,z),t) */ testGetComponentAt( - null, // Null because our CRS has no component for the 'x' axis alone. - null, // Null because our CRS has no component for the 'y' axis alone. + null, // Null because our CRS has no component for the `x` axis alone. + null, // Null because our CRS has no component for the `y` axis alone. HardCodedCRS.GRAVITY_RELATED_HEIGHT, HardCodedCRS.TIME, HardCodedCRS.WGS84, @@ -473,13 +463,8 @@ public final class CRSTest extends TestCase { */ @Test public void testCompound() throws FactoryException { - try { - CRS.compound(); - fail("Should not accept empty array."); - } catch (IllegalArgumentException e) { - final String message = e.getMessage(); - assertTrue(message, message.contains("components")); - } + var e = assertThrows(IllegalArgumentException.class, () -> CRS.compound()); + assertMessageContains(e, "components"); assertSame(HardCodedCRS.WGS84, CRS.compound(HardCodedCRS.WGS84)); assertEqualsIgnoreMetadata(HardCodedCRS.WGS84_3D, CRS.compound(HardCodedCRS.WGS84, HardCodedCRS.ELLIPSOIDAL_HEIGHT)); } @@ -498,29 +483,29 @@ public final class CRSTest extends TestCase { final CoordinateReferenceSystem xyz, final CoordinateReferenceSystem xyzt) { - assertSame("[0…4]", xyzt, CRS.getComponentAt(xyzt, 0, 4)); - assertSame("[0…3]", xyz, CRS.getComponentAt(xyzt, 0, 3)); - assertSame("[0…2]", xy, CRS.getComponentAt(xyzt, 0, 2)); - assertSame("[0…1]", x, CRS.getComponentAt(xyzt, 0, 1)); - assertSame("[1…2]", y, CRS.getComponentAt(xyzt, 1, 2)); - assertSame("[2…3]", z, CRS.getComponentAt(xyzt, 2, 3)); - assertSame("[3…4]", t, CRS.getComponentAt(xyzt, 3, 4)); - assertNull("[1…3]", CRS.getComponentAt(xyzt, 1, 3)); - assertNull("[1…4]", CRS.getComponentAt(xyzt, 1, 4)); - assertNull("[2…4]", CRS.getComponentAt(xyzt, 2, 4)); - assertNull("[4…4]", CRS.getComponentAt(xyzt, 4, 4)); + assertSame(xyzt, CRS.getComponentAt(xyzt, 0, 4)); + assertSame(xyz, CRS.getComponentAt(xyzt, 0, 3)); + assertSame(xy, CRS.getComponentAt(xyzt, 0, 2)); + assertSame(x, CRS.getComponentAt(xyzt, 0, 1)); + assertSame(y, CRS.getComponentAt(xyzt, 1, 2)); + assertSame(z, CRS.getComponentAt(xyzt, 2, 3)); + assertSame(t, CRS.getComponentAt(xyzt, 3, 4)); + assertNull( CRS.getComponentAt(xyzt, 1, 3)); + assertNull( CRS.getComponentAt(xyzt, 1, 4)); + assertNull( CRS.getComponentAt(xyzt, 2, 4)); + assertNull( CRS.getComponentAt(xyzt, 4, 4)); if (xyz != null) { - assertSame("[0…3]", xyz, CRS.getComponentAt(xyz, 0, 3)); - assertSame("[0…2]", xy, CRS.getComponentAt(xyz, 0, 2)); - assertSame("[0…1]", x, CRS.getComponentAt(xyz, 0, 1)); - assertSame("[1…2]", y, CRS.getComponentAt(xyz, 1, 2)); - assertSame("[2…3]", z, CRS.getComponentAt(xyz, 2, 3)); + assertSame(xyz, CRS.getComponentAt(xyz, 0, 3)); + assertSame(xy, CRS.getComponentAt(xyz, 0, 2)); + assertSame(x, CRS.getComponentAt(xyz, 0, 1)); + assertSame(y, CRS.getComponentAt(xyz, 1, 2)); + assertSame(z, CRS.getComponentAt(xyz, 2, 3)); } if (xy != null) { - assertSame("[0…2]", xy, CRS.getComponentAt(xy, 0, 2)); - assertSame("[0…1]", x, CRS.getComponentAt(xy, 0, 1)); - assertSame("[1…2]", y, CRS.getComponentAt(xy, 1, 2)); + assertSame(xy, CRS.getComponentAt(xy, 0, 2)); + assertSame(x, CRS.getComponentAt(xy, 0, 1)); + assertSame(y, CRS.getComponentAt(xy, 1, 2)); } } @@ -529,8 +514,8 @@ public final class CRSTest extends TestCase { */ @Test public void testGetGreenwichLongitude() { - assertEquals(0, CRS.getGreenwichLongitude(HardCodedCRS.WGS84), STRICT); - assertEquals(2.33722917, CRS.getGreenwichLongitude(HardCodedCRS.NTF), 1E-12); + assertEquals(0, CRS.getGreenwichLongitude(HardCodedCRS.WGS84)); + assertEquals(2.33722917, CRS.getGreenwichLongitude(HardCodedCRS.NTF), 1E-12); } /** diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java index d82bc971ff..23a64bd4f7 100644 --- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java +++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/io/stream/ChannelDataOutputTest.java @@ -353,7 +353,7 @@ public final class ChannelDataOutputTest extends ChannelDataTestCase { /* * Verify that we have no remaining marks, and finally compare stream content. */ - IOException exception = assertThrows(IOException.class, () -> testedStream.reset()); + var exception = assertThrows(IOException.class, () -> testedStream.reset()); assertMessageContains(exception); assertStreamContentEquals(); } diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java index 5569206dc2..76c81eef9e 100644 --- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java +++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/FeatureQueryTest.java @@ -435,7 +435,7 @@ public final class FeatureQueryTest extends TestCase { query.setProjection(new FeatureQuery.NamedExpression(ff.property("value1", Integer.class), (String) null), virtualProjection(ff.property("valueMissing", Integer.class), "renamed1")); - DataStoreContentException exception = assertThrows(DataStoreContentException.class, this::executeAndGetFirst); + var exception = assertThrows(DataStoreContentException.class, this::executeAndGetFirst); assertMessageContains(exception); } } diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java index e472596ffb..2ad3400bef 100644 --- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java +++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/StorageConnectorTest.java @@ -417,7 +417,7 @@ public final class StorageConnectorTest extends TestCase { assertNull (connector.getStorageAs(URI.class)); assertNull (connector.getStorageAs(String.class)); - UnconvertibleObjectException exception = assertThrows(UnconvertibleObjectException.class, + var exception = assertThrows(UnconvertibleObjectException.class, () -> connector.getStorageAs(Float.class), "Should not accept Float.class"); assertMessageContains(exception, "Float"); connector.closeAllExcept(null); @@ -452,7 +452,7 @@ public final class StorageConnectorTest extends TestCase { final StorageConnector connector = create(false); final InputStream stream = connector.commit(InputStream.class, "Test"); - IllegalStateException exception = assertThrows(IllegalStateException.class, + var exception = assertThrows(IllegalStateException.class, () -> connector.getStorageAs(ByteBuffer.class), "Connector should be closed."); assertMessageContains(exception); assertExpectedBytes(stream); diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/internal/RewindableLineReaderTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/internal/RewindableLineReaderTest.java index 1126786913..8be4650451 100644 --- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/internal/RewindableLineReaderTest.java +++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/internal/RewindableLineReaderTest.java @@ -77,7 +77,8 @@ public final class RewindableLineReaderTest extends TestCase { final RewindableLineReader old = reader; reader = reader.rewind(); // Should be a new instance, but this is not mandatory. if (reader != old) { - assertThrows(IOException.class, () -> old.read()); + var e = assertThrows(IOException.class, () -> old.read()); + assertNotNull(e.getMessage()); } assertEquals('A', reader.read()); assertEquals('B', reader.read());