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 1cb414e6a2633b6ba4916d888fc1d7f8233005ee Author: Martin Desruisseaux <[email protected]> AuthorDate: Wed Jun 8 13:19:20 2022 +0200 Add documentation, code formatting and import statements order. --- .../internal/filter/sqlmm/FunctionWithSRID.java | 3 +- .../sis/internal/filter/sqlmm/SQLMMTest.java | 74 +++++++++++++++------- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/FunctionWithSRID.java b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/FunctionWithSRID.java index 237588b1c9..08a167efe8 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/FunctionWithSRID.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/FunctionWithSRID.java @@ -43,7 +43,8 @@ import org.opengis.filter.InvalidFilterValueException; * * @author Johann Sorel (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @author Alexis Manin (Geomatys) + * @version 1.3 * * @param <R> the type of resources (e.g. {@link org.opengis.feature.Feature}) used as inputs. * diff --git a/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java b/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java index 0c41d149ad..9d889701dc 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/internal/filter/sqlmm/SQLMMTest.java @@ -17,30 +17,33 @@ package org.apache.sis.internal.filter.sqlmm; import java.util.function.BiFunction; -import org.apache.sis.internal.feature.jts.JTS; -import org.apache.sis.referencing.crs.HardCodedCRS; +import org.opengis.util.FactoryException; +import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.locationtech.jts.geom.Point; -import org.opengis.feature.Feature; -import org.opengis.filter.Expression; -import org.opengis.filter.FilterFactory; import org.locationtech.jts.geom.Polygon; +import org.apache.sis.internal.feature.jts.JTS; +import org.apache.sis.referencing.crs.HardCodedCRS; import org.apache.sis.filter.DefaultFilterFactory; import org.apache.sis.referencing.CommonCRS; import org.apache.sis.test.TestCase; import org.junit.Test; -import org.opengis.filter.Literal; -import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.opengis.util.FactoryException; import static org.opengis.test.Assert.*; +// Branch-dependent imports +import org.opengis.filter.Literal; +import org.opengis.feature.Feature; +import org.opengis.filter.Expression; +import org.opengis.filter.FilterFactory; + /** * Apply some validation on the {@link SQLMM} enumeration. * * @author Martin Desruisseaux (Geomatys) * @author Johann Sorel (Geomatys) - * @version 1.2 + * @author Alexis Manin (Geomatys) + * @version 1.3 * @since 1.1 * @module */ @@ -85,31 +88,54 @@ public final strictfp class SQLMMTest extends TestCase { assertEquals(CommonCRS.WGS84.geographic(), polygon.getUserData()); } + /** + * Tests {@link FilterFactory#function(String, Expression...)} where the last argument + * is an optional CRS. The {@code ST_Point} function is used for this test. + * + * @throws FactoryException if an error occurred while fetching the CRS from a JTS geometry. + */ @Test - public void testOptionalCrsInSTPoint() throws Exception { - // Ensure that when argument array is of size 2, the FunctionWithSRID constructor will not fail with an ArrayIndexOutOfBoundsException. - // This is important. This case has already happen, making it a regression test. - assertPoint(null, (x, y) -> new Expression[] { x, y }); - // Ensure point function will correctly interpret a literal with a null value as "no crs available" - assertPoint(null, (x, y) -> new Expression[] { x, y, factory.literal(null) }); - // Ensure CRS is fetched properly - assertPoint(HardCodedCRS.WGS84, (x, y) -> new Expression[]{ x, y, factory.literal(HardCodedCRS.WGS84) }); + @SuppressWarnings({"rawtypes", "unchecked"}) // Because of generic array creation. + public void testOptionalCrsInSTPoint() throws FactoryException { + /* + * Ensure that when argument array is of size 2, the `FunctionWithSRID` + * constructor will not fail with an `ArrayIndexOutOfBoundsException`. + * This bug happened in SIS 1.2. + */ + verifyPoint(null, (x, y) -> new Expression[] { x, y }); + /* + * Ensure that point function will correctly interpret + * a literal with a null value as "no CRS available". + */ + verifyPoint(null, (x, y) -> new Expression[] { x, y, factory.literal(null) }); + /* + * Ensure that CRS is fetched properly. + */ + verifyPoint(HardCodedCRS.WGS84, (x, y) -> new Expression[] { x, y, factory.literal(HardCodedCRS.WGS84) }); } /** - * Verify that a point function properly build a point with expected CRS and coordinate. + * Verifies that a point function properly build a point with expected CRS and coordinate. + * + * @param expectedCRS the CRS that should be found in the point created with {@code argumentBundler}. + * @param argumentBundler given (x,y) coordinates, provides the list of arguments for {@code ST_Point(…)}. + * @throws FactoryException if an error occurred while fetching the CRS from a JTS geometry. */ - private void assertPoint(CoordinateReferenceSystem expectedCrs, BiFunction<Expression<Feature, Double>, Expression<Feature, Double>, Expression[]> argumentBundler) throws FactoryException { + private void verifyPoint(final CoordinateReferenceSystem expectedCRS, + final BiFunction<Expression<Feature, Double>, + Expression<Feature, Double>, + Expression<Feature, ?>[]> argumentBundler) + throws FactoryException + { final Literal<Feature, Double> x = factory.literal(1.0); final Literal<Feature, Double> y = factory.literal(2.0); Expression<Feature, ?> fn = factory.function("ST_Point", argumentBundler.apply(x, y)); Object rawPoint = fn.apply(null); assertInstanceOf("ST_Point should create a Point geometry", Point.class, rawPoint); Point point = (Point) rawPoint; - final CoordinateReferenceSystem pointCrs = JTS.getCoordinateReferenceSystem(point); - if (expectedCrs == null) assertNull("Point CRS", pointCrs); - else assertEquals("Point CRS", expectedCrs, pointCrs); - assertEquals(point.getX(), x.getValue(), 1e-1); - assertEquals(point.getY(), y.getValue(), 1e-1); + CoordinateReferenceSystem pointCRS = JTS.getCoordinateReferenceSystem(point); + assertEquals("Point CRS", expectedCRS, pointCRS); + assertEquals(point.getX(), x.getValue(), STRICT); + assertEquals(point.getY(), y.getValue(), STRICT); } }
