sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1679046 - in /sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation: DefaultConversionTest.java DefaultTransformationTest.java
Date Tue, 12 May 2015 20:15:12 GMT
Author: desruisseaux
Date: Tue May 12 20:15:11 2015
New Revision: 1679046

URL: http://svn.apache.org/r1679046
Log:
Referencing: minor tests consolidation.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java?rev=1679046&r1=1679045&r2=1679046&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConversionTest.java
[UTF-8] Tue May 12 20:15:11 2015
@@ -87,18 +87,28 @@ public final strictfp class DefaultConve
      * @param targetCRS A CRS using the Greenwich prime meridian.
      */
     private static DefaultConversion createLongitudeRotation(final GeographicCRS sourceCRS,
final GeographicCRS targetCRS) {
-        final Matrix rotation = Matrices.createDiagonal(
-                targetCRS.getCoordinateSystem().getDimension() + 1,     // Number of rows.
-                sourceCRS.getCoordinateSystem().getDimension() + 1);    // Number of columns.
-        rotation.setElement(0, rotation.getNumCol() - 1, OFFSET);
-
+        /*
+         * The following code fills the parameter values AND creates itself the MathTransform
instance
+         * (indirectly, through the matrix). The later step is normally not our business,
since we are
+         * supposed to only fill the parameter values and let MathTransformFactory creates
the transform
+         * from the parameters. But we don't do the normal steps here because this class
is a unit test:
+         * we want to test DefaultConversion in isolation of MathTransformFactory.
+         */
+        final int srcDim = sourceCRS.getCoordinateSystem().getDimension();
+        final int tgtDim = targetCRS.getCoordinateSystem().getDimension();
         final OperationMethod method = DefaultOperationMethodTest.create(
-                "Longitude rotation", "9601", "EPSG guidance note #7-2",
-                sourceCRS.getCoordinateSystem().getDimension(),
+                "Longitude rotation", "9601", "EPSG guidance note #7-2", srcDim,
                 DefaultParameterDescriptorTest.createEPSG("Longitude offset", (short) 9601));
         final ParameterValueGroup pg = method.getParameters().createValue();
         pg.parameter("Longitude offset").setValue(OFFSET);
-
+        final Matrix rotation = Matrices.createDiagonal(tgtDim + 1, srcDim + 1);
+        rotation.setElement(0, srcDim, OFFSET);
+        /*
+         * In theory we should not need to provide the parameters explicitly to the constructor
since
+         * we are supposed to be able to find them from the MathTransform. But in this simple
test we
+         * did not bothered to define a specialized MathTransform class for our case. So
we will help
+         * a little bit DefaultConversion by telling it the parameters that we used.
+         */
         final Map<String, Object> properties = new HashMap<>(4);
         properties.put(DefaultTransformation.NAME_KEY, "Paris to Greenwich");
         properties.put(OperationMethods.PARAMETERS_KEY, pg);
@@ -106,11 +116,10 @@ public final strictfp class DefaultConve
     }
 
     /**
-     * Tests a simple two-dimensional conversion performing a longitude rotation on the WGS84
datum.
+     * Asserts that at least some of the properties of the given {@code op} instance have
the expected values
+     * for an instance created by {@link #createLongitudeRotation(GeographicCRS, GeographicCRS)}.
      */
-    @Test
-    public void testConstruction() {
-        final DefaultConversion op = createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_2D),
HardCodedCRS.WGS84);
+    private static void verifyProperties(final DefaultConversion op) {
         assertEquals("name",       "Paris to Greenwich", op.getName().getCode());
         assertEquals("sourceCRS",  "Paris",              op.getSourceCRS().getName().getCode());
         assertEquals("targetCRS",  "WGS 84",             op.getTargetCRS().getName().getCode());
@@ -122,6 +131,7 @@ public final strictfp class DefaultConve
         assertEquals("parameters",    "Longitude rotation", parameters.getDescriptor().getName().getCode());
         assertEquals("parameters[0]", "Longitude offset",    values[0].getDescriptor().getName().getCode());
         assertEquals("parameters[0]", OFFSET, values[0].doubleValue(), STRICT);
+        assertEquals(1, values.length);
 
         final Matrix m = MathTransforms.getMatrix(op.getMathTransform());
         assertNotNull("transform", m);
@@ -134,11 +144,20 @@ public final strictfp class DefaultConve
     }
 
     /**
+     * Tests a simple two-dimensional conversion performing a longitude rotation on the WGS84
datum.
+     */
+    @Test
+    public void testConstruction() {
+        verifyProperties(createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_2D),
HardCodedCRS.WGS84));
+    }
+
+    /**
      * Tests serialization.
      */
     @Test
     @DependsOnMethod("testConstruction")
     public void testSerialization() {
-        assertSerializedEquals(createLongitudeRotation(createParisCRS(HardCodedCS.GEODETIC_2D),
HardCodedCRS.WGS84));
+        verifyProperties(assertSerializedEquals(createLongitudeRotation(
+                createParisCRS(HardCodedCS.GEODETIC_2D), HardCodedCRS.WGS84)));
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java?rev=1679046&r1=1679045&r2=1679046&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java
[UTF-8] Tue May 12 20:15:11 2015
@@ -75,6 +75,13 @@ public final strictfp class DefaultTrans
      * Creates a “Tokyo to JGD2000 (GSI)” transformation.
      */
     private static DefaultTransformation createGeocentricTranslation() {
+        /*
+         * The following code fills the parameter values AND creates itself the MathTransform
instance
+         * (indirectly, through the matrix). The later step is normally not our business,
since we are
+         * supposed to only fill the parameter values and let MathTransformFactory creates
the transform
+         * from the parameters. But we don't do the normal steps here because this class
is a unit test:
+         * we want to test DefaultTransformation in isolation of MathTransformFactory.
+         */
         final Matrix4 translation = new Matrix4();
         final OperationMethod method = DefaultOperationMethodTest.create(
                 "Geocentric translations", "1031", "EPSG guidance note #7-2", 3,
@@ -85,6 +92,12 @@ public final strictfp class DefaultTrans
         pg.parameter("X-axis translation").setValue(translation.m02 = -146.414);
         pg.parameter("Y-axis translation").setValue(translation.m12 =  507.337);
         pg.parameter("Z-axis translation").setValue(translation.m22 =  680.507);
+        /*
+         * In theory we should not need to provide the parameters explicitly to the constructor
since
+         * we are supposed to be able to find them from the MathTransform. But in this simple
test we
+         * did not bothered to define a specialized MathTransform class for our case. So
we will help
+         * a little bit DefaultTransformation by telling it the parameters that we used.
+         */
         final Map<String, Object> properties = new HashMap<>(4);
         properties.put(DefaultTransformation.NAME_KEY, "Tokyo to JGD2000 (GSI)");
         properties.put(OperationMethods.PARAMETERS_KEY, pg);
@@ -97,11 +110,10 @@ public final strictfp class DefaultTrans
     }
 
     /**
-     * Tests construction.
+     * Asserts that at least some of the properties of the given {@code op} instance have
the expected values
+     * for an instance created by {@link #createGeocentricTranslation()}.
      */
-    @Test
-    public void testConstruction() {
-        final DefaultTransformation op = createGeocentricTranslation();
+    private static void verifyProperties(final DefaultTransformation op) {
         assertEquals("name",       "Tokyo to JGD2000 (GSI)",  op.getName().getCode());
         assertEquals("sourceCRS",  "Tokyo 1918",              op.getSourceCRS().getName().getCode());
         assertEquals("targetCRS",  "JGD2000",                 op.getTargetCRS().getName().getCode());
@@ -117,6 +129,7 @@ public final strictfp class DefaultTrans
         assertEquals("parameters[0]", -146.414, values[0].doubleValue(), STRICT);
         assertEquals("parameters[1]",  507.337, values[1].doubleValue(), STRICT);
         assertEquals("parameters[2]",  680.507, values[2].doubleValue(), STRICT);
+        assertEquals(3, values.length);
 
         final Matrix m = MathTransforms.getMatrix(op.getMathTransform());
         assertNotNull("transform", m);
@@ -134,6 +147,14 @@ public final strictfp class DefaultTrans
     }
 
     /**
+     * Tests construction.
+     */
+    @Test
+    public void testConstruction() {
+        verifyProperties(createGeocentricTranslation());
+    }
+
+    /**
      * Tests WKT formatting.
      */
     @Test
@@ -195,6 +216,6 @@ public final strictfp class DefaultTrans
     @Test
     @DependsOnMethod("testConstruction")
     public void testSerialization() {
-        assertSerializedEquals(createGeocentricTranslation());
+        verifyProperties(assertSerializedEquals(createGeocentricTranslation()));
     }
 }



Mime
View raw message