sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1809632 - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/builder/ sis-feature/src/test/java/org/apache/sis/feature/builder/ sis-feature/src/test/java/org/apache/sis/test/suite/ sis-referencing/src/main/java/or...
Date Mon, 25 Sep 2017 14:09:04 GMT
Author: desruisseaux
Date: Mon Sep 25 14:09:04 2017
New Revision: 1809632

URL: http://svn.apache.org/viewvc?rev=1809632&view=rev
Log:
Add tests submitted by Michael Hausegger on https://github.com/apache/sis/pull/2
Tests have been refactored. As a side-effect, we did minor adjustments in
Envelope.getMinimum/getMaximum() and FeatureTypeBuilder.setSuperTypes(…).

Added:
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AssociationRoleBuilderTest.java
  (with props)
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ArrayEnvelopeTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ImmutableEnvelopeTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -407,9 +407,10 @@ public class FeatureTypeBuilder extends
 
     /**
      * Sets the parent types (or super-type) from which to inherit properties.
-     * If this method is not invoked, then the default value is to have no parent.
+     * If this method is not invoked, then the default value is no parent.
      *
      * @param  parents  the parent types from which to inherit properties, or an empty array
if none.
+     *                  Null elements are ignored.
      * @return {@code this} for allowing method calls chaining.
      */
     public FeatureTypeBuilder setSuperTypes(final FeatureType... parents) {
@@ -418,6 +419,11 @@ public class FeatureTypeBuilder extends
         if (!superTypes.equals(asList)) {
             superTypes.clear();
             superTypes.addAll(asList);
+            for (int i=superTypes.size(); --i >= 0;) {
+                if (superTypes.get(i) == null) {
+                    superTypes.remove(i);
+                }
+            }
             clearCache();
         }
         return this;

Added: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AssociationRoleBuilderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AssociationRoleBuilderTest.java?rev=1809632&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AssociationRoleBuilderTest.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AssociationRoleBuilderTest.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.feature.builder;
+
+import org.apache.sis.referencing.NamedIdentifier;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+// Branch-dependent imports
+import org.opengis.feature.FeatureAssociationRole;
+
+
+/**
+ * Unit tests for class {@link AssociationRoleBuilder}.
+ *
+ * @author  Michael Hausegger
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+public final strictfp class AssociationRoleBuilderTest extends TestCase {
+    /**
+     * Tests the name, designation, definition, description and cardinality associated to
the role.
+     */
+    @Test
+    public void testMetadata() {
+        final FeatureTypeBuilder ftb = new FeatureTypeBuilder().setName("Highway");
+        final NamedIdentifier target = new NamedIdentifier(null, "Bridge");
+        final AssociationRoleBuilder builder = new AssociationRoleBuilder(ftb, null, target)
+                .setDescription("Bridges on the highway")
+                .setDefinition("A definition")
+                .setDesignation("A designation")
+                .setMaximumOccurs(2)
+                .setMinimumOccurs(1);
+
+        final FeatureAssociationRole role = builder.build();
+        assertEquals("minimumOccurs", 1, role.getMinimumOccurs());
+        assertEquals("maximumOccurs", 2, role.getMaximumOccurs());
+        assertEquals("designation", new SimpleInternationalString("A designation"),     
    role.getDesignation());
+        assertEquals("definition",  new SimpleInternationalString("A definition"),      
    role.getDefinition());
+        assertEquals("description", new SimpleInternationalString("Bridges on the highway"),
role.getDescription());
+    }
+}

Propchange: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AssociationRoleBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AssociationRoleBuilderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -20,8 +20,8 @@ import java.util.Iterator;
 import java.util.Collections;
 import com.esri.core.geometry.Geometry;
 import com.esri.core.geometry.Point;
-import org.apache.sis.feature.AbstractOperation;
 import org.opengis.geometry.Envelope;
+import org.apache.sis.feature.AbstractOperation;
 import org.apache.sis.internal.feature.AttributeConvention;
 import org.apache.sis.feature.DefaultFeatureTypeTest;
 import org.apache.sis.feature.FeatureOperations;
@@ -47,6 +47,7 @@ import org.opengis.feature.Operation;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Michael Hausegger
  * @version 0.8
  * @since   0.8
  * @module
@@ -54,9 +55,56 @@ import org.opengis.feature.Operation;
 @DependsOn(AttributeTypeBuilderTest.class)
 public final strictfp class FeatureTypeBuilderTest extends TestCase {
     /**
+     * Verifies that {@link FeatureTypeBuilder#setSuperTypes(FeatureType...)} ignores null
parents.
+     * This method tests only the builder state without creating feature type.
+     */
+    @Test
+    public void testNullParents() {
+        final FeatureTypeBuilder builder = new FeatureTypeBuilder(null);
+        assertSame(builder, builder.setSuperTypes(new FeatureType[6]));
+        assertEquals(0, builder.getSuperTypes().length);
+    }
+
+    /**
+     * Verifies {@link FeatureTypeBuilder#setAbstract(boolean)}.
+     * This method tests only the builder state without creating feature type.
+     */
+    @Test
+    public void testSetAbstract() {
+        final FeatureTypeBuilder builder = new FeatureTypeBuilder(null);
+        assertFalse("isAbstract", builder.isAbstract());
+        assertSame (builder, builder.setAbstract(true));
+        assertTrue ("isAbstract", builder.isAbstract());
+    }
+
+    /**
+     * Verifies {@link FeatureTypeBuilder#setDeprecated(boolean)}.
+     * This method tests only the builder state without creating feature type.
+     */
+    @Test
+    public void testSetDeprecated() {
+        FeatureTypeBuilder builder = new FeatureTypeBuilder();
+        assertFalse("isDeprecated", builder.isDeprecated());
+        builder.setDeprecated(true);
+        assertTrue("isDeprecated", builder.isDeprecated());
+    }
+
+    /**
+     * Verifies {@link FeatureTypeBuilder#setNameSpace(CharSequence)}.
+     */
+    @Test
+    public void testSetNameSpace() {
+        final FeatureTypeBuilder builder = new FeatureTypeBuilder();
+        assertNull("nameSpace", builder.getNameSpace());
+        assertSame(builder, builder.setNameSpace("myNameSpace"));
+        assertEquals("nameSpace", "myNameSpace", builder.getNameSpace());
+    }
+
+    /**
      * Tests with the minimum number of parameters (no property and no super type).
      */
     @Test
+    @DependsOnMethod({"testSetAbstract", "testSetDeprecated", "testSetNameSpace"})
     public void testInitialization() {
         final FeatureTypeBuilder builder = new FeatureTypeBuilder();
         try {

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -54,6 +54,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.feature.AttributeConventionTest.class,
     org.apache.sis.feature.builder.CharacteristicTypeBuilderTest.class,
     org.apache.sis.feature.builder.AttributeTypeBuilderTest.class,
+    org.apache.sis.feature.builder.AssociationRoleBuilderTest.class,
     org.apache.sis.feature.builder.FeatureTypeBuilderTest.class
 })
 public final strictfp class FeatureTestSuite extends TestSuite {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -213,7 +213,17 @@ public abstract class AbstractEnvelope i
      * @return {@code true} if the range meaning is {@code WRAPAROUND}.
      */
     static boolean isWrapAround(final CoordinateReferenceSystem crs, final int dimension)
{
-        final CoordinateSystemAxis axis = getAxis(crs, dimension);
+        return isWrapAround(getAxis(crs, dimension));
+    }
+
+    /**
+     * Returns {@code true} if the given axis is non-null and has the
+     * {@link RangeMeaning#WRAPAROUND WRAPAROUND} range meaning.
+     *
+     * @param  axis  the axis to test, or {@code null}.
+     * @return {@code true} if the range meaning is {@code WRAPAROUND}.
+     */
+    static boolean isWrapAround(final CoordinateSystemAxis axis) {
         return (axis != null) && RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning());
     }
 
@@ -225,7 +235,7 @@ public abstract class AbstractEnvelope i
      * @return the spanning of the given axis.
      */
     static double getSpan(final CoordinateSystemAxis axis) {
-        if (axis != null && RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning()))
{
+        if (isWrapAround(axis)) {
             return axis.getMaximumValue() - axis.getMinimumValue();
         }
         return Double.NaN;
@@ -338,9 +348,10 @@ public abstract class AbstractEnvelope i
 
     /**
      * Returns the minimal ordinate value for the specified dimension. In the typical case
-     * of envelopes <em>not</em> spanning the anti-meridian, this method returns
the
+     * of non-empty envelopes <em>not</em> spanning the anti-meridian, this method
returns the
      * {@link #getLower(int)} value verbatim. In the case of envelope spanning the anti-meridian,
      * this method returns the {@linkplain CoordinateSystemAxis#getMinimumValue() axis minimum
value}.
+     * If the range in the given dimension is invalid, then this method returns {@code NaN}.
      *
      * @param  dimension  the dimension for which to obtain the ordinate value.
      * @return the minimal ordinate value at the given dimension.
@@ -352,16 +363,17 @@ public abstract class AbstractEnvelope i
         double lower = getLower(dimension);
         if (isNegative(getUpper(dimension) - lower)) {              // Special handling for
-0.0
             final CoordinateSystemAxis axis = getAxis(getCoordinateReferenceSystem(), dimension);
-            lower = (axis != null) ? axis.getMinimumValue() : Double.NEGATIVE_INFINITY;
+            lower = isWrapAround(axis) ? axis.getMinimumValue() : Double.NaN;
         }
         return lower;
     }
 
     /**
      * Returns the maximal ordinate value for the specified dimension. In the typical case
-     * of envelopes <em>not</em> spanning the anti-meridian, this method returns
the
+     * of non-empty envelopes <em>not</em> spanning the anti-meridian, this method
returns the
      * {@link #getUpper(int)} value verbatim. In the case of envelope spanning the anti-meridian,
      * this method returns the {@linkplain CoordinateSystemAxis#getMaximumValue() axis maximum
value}.
+     * If the range in the given dimension is invalid, then this method returns {@code NaN}.
      *
      * @param  dimension  the dimension for which to obtain the ordinate value.
      * @return the maximal ordinate value at the given dimension.
@@ -373,7 +385,7 @@ public abstract class AbstractEnvelope i
         double upper = getUpper(dimension);
         if (isNegative(upper - getLower(dimension))) {              // Special handling for
-0.0
             final CoordinateSystemAxis axis = getAxis(getCoordinateReferenceSystem(), dimension);
-            upper = (axis != null) ? axis.getMaximumValue() : Double.POSITIVE_INFINITY;
+            upper = isWrapAround(axis) ? axis.getMaximumValue() : Double.NaN;
         }
         return upper;
     }
@@ -417,7 +429,7 @@ public abstract class AbstractEnvelope i
      * If no shift can be applied, returns {@code NaN}.
      */
     static double fixMedian(final CoordinateSystemAxis axis, final double median) {
-        if (axis != null && RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning()))
{
+        if (isWrapAround(axis)) {
             final double minimum = axis.getMinimumValue();
             final double maximum = axis.getMaximumValue();
             final double cycle   = maximum - minimum;
@@ -468,7 +480,7 @@ public abstract class AbstractEnvelope i
      * @return a positive span, or NaN if the span can not be fixed.
      */
     static double fixSpan(final CoordinateSystemAxis axis, double span) {
-        if (axis != null && RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning()))
{
+        if (isWrapAround(axis)) {
             final double cycle = axis.getMaximumValue() - axis.getMinimumValue();
             if (cycle > 0 && cycle != Double.POSITIVE_INFINITY) {
                 span += cycle;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -459,7 +459,7 @@ scanNumber: while ((i += Character.charC
         double lower = ordinates[i];
         if (isNegative(ordinates[i + (ordinates.length >>> 1)] - lower)) {     
// Special handling for -0.0
             final CoordinateSystemAxis axis = getAxis(crs, dimension);
-            lower = (axis != null) ? axis.getMinimumValue() : Double.NEGATIVE_INFINITY;
+            lower = isWrapAround(axis) ? axis.getMinimumValue() : Double.NaN;
         }
         return lower;
     }
@@ -474,7 +474,7 @@ scanNumber: while ((i += Character.charC
         double upper = ordinates[i + (ordinates.length >>> 1)];
         if (isNegative(upper - ordinates[i])) {                                 // Special
handling for -0.0
             final CoordinateSystemAxis axis = getAxis(crs, dimension);
-            upper = (axis != null) ? axis.getMaximumValue() : Double.POSITIVE_INFINITY;
+            upper = isWrapAround(axis) ? axis.getMaximumValue() : Double.NaN;
         }
         return upper;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -32,8 +32,6 @@ import org.apache.sis.util.Emptiable;
 
 import static java.lang.Double.NaN;
 import static java.lang.Double.isNaN;
-import static java.lang.Double.POSITIVE_INFINITY;
-import static java.lang.Double.NEGATIVE_INFINITY;
 import static java.lang.Double.doubleToLongBits;
 import static org.apache.sis.math.MathFunctions.isPositive;
 import static org.apache.sis.math.MathFunctions.isNegative;
@@ -388,7 +386,7 @@ public class Envelope2D extends Rectangl
         }
         if (isNegative(span)) {                                         // Special handling
for -0.0
             final CoordinateSystemAxis axis = getAxis(crs, dimension);
-            return (axis != null) ? axis.getMinimumValue() : NEGATIVE_INFINITY;
+            return isWrapAround(axis) ? axis.getMinimumValue() : NaN;
         }
         return value;
     }
@@ -412,7 +410,7 @@ public class Envelope2D extends Rectangl
         }
         if (isNegative(span)) {                                         // Special handling
for -0.0
             final CoordinateSystemAxis axis = getAxis(crs, dimension);
-            return (axis != null) ? axis.getMaximumValue() : POSITIVE_INFINITY;
+            return isWrapAround(axis) ? axis.getMaximumValue() : NaN;
         }
         return value + span;
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -103,6 +103,8 @@ public final class Envelopes extends Sta
 
     /**
      * Returns {@code true} if the given axis is of kind "Wrap Around".
+     *
+     * @see AbstractEnvelope#isWrapAround(CoordinateSystemAxis)
      */
     static boolean isWrapAround(final CoordinateSystemAxis axis) {
         return RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning());

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -978,7 +978,7 @@ public class GeneralEnvelope extends Arr
             final double upper = ordinates[iUpper];
             if (isNegative(upper - lower)) {
                 final CoordinateSystemAxis axis = getAxis(crs, i);
-                if (axis != null && RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning()))
{
+                if (isWrapAround(axis)) {
                     ordinates[iLower] = axis.getMinimumValue();
                     ordinates[iUpper] = axis.getMaximumValue();
                     changed = true;

Added: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ArrayEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ArrayEnvelopeTest.java?rev=1809632&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ArrayEnvelopeTest.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ArrayEnvelopeTest.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.geometry;
+
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Unit tests for class {@link ArrayEnvelope}.
+ * This is the base class of {@link GeneralEnvelope} and {@link ImmutableEnvelope}.
+ *
+ * @author  Michael Hausegger
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+@DependsOn(AbstractEnvelopeTest.class)
+public final strictfp class ArrayEnvelopeTest extends TestCase {
+    /**
+     * Tests {@link ArrayEnvelope#isEmpty()}.
+     */
+    @Test
+    public void testIsEmpty() {
+        ArrayEnvelope envelope = new ArrayEnvelope(new double[] {0, -356.683168});
+        assertTrue(envelope.isEmpty());
+        envelope.ordinates[0] = -360;
+        assertFalse(envelope.isEmpty());
+    }
+
+    /**
+     * Tests {@link ArrayEnvelope#getMinimum(int)} and {@link ArrayEnvelope#getMaximum(int)}.
+     */
+    @Test
+    public void testGetExtremums() {
+        ArrayEnvelope envelope = new ArrayEnvelope(2);
+        envelope.ordinates[2] = -1728;
+        assertTrue(Double.isNaN(envelope.getMinimum(0)));
+        assertTrue(Double.isNaN(envelope.getMaximum(0)));
+        assertEquals(0, envelope.getMinimum(1), STRICT);
+        assertEquals(0, envelope.getMaximum(1), STRICT);
+
+        // Make the range valid and test again.
+        envelope.ordinates[0] = -1800;
+        assertEquals(-1800, envelope.getMinimum(0), STRICT);
+        assertEquals(-1728, envelope.getMaximum(0), STRICT);
+    }
+
+    /**
+     * Tests envelope construction from a the pseudo-Well Known Text (WKT) representation
of a Bounding Box (BBOX).
+     */
+    @Test
+    public void testCreatesFromWKT() {
+        ArrayEnvelope envelope = new ArrayEnvelope(
+                "BOX6D(-5610.14928 -3642.5148 1957.4432 -170.0175 -77.9698 -Infinity,"
+                   + " -5610.14920 -3642.5140 1957.4440 -170.0170 -77.9690 -Infinity)");
+        assertEquals(6, envelope.getDimension());
+        assertArrayEquals(new double[] {
+            -5610.14928, -3642.5148, 1957.4432, -170.0175, -77.9698, Double.NEGATIVE_INFINITY,
+            -5610.14920, -3642.5140, 1957.4440, -170.0170, -77.9690, Double.NEGATIVE_INFINITY
+        }, envelope.ordinates, STRICT);
+    }
+
+    /**
+     * Verifies that attempt to create an envelope from an invalid WKT results in an exception.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testCreatesFromInvalidWKT() {
+        assertNotNull(new ArrayEnvelope("BBOX[\"invalid\"]").ordinates);
+    }
+
+    /**
+     * Verifies the creation of dimensionless envelopes (envelopes having zero dimension).
+     */
+    @Test
+    public void testDimensionlessEnvelope() {
+        ArrayEnvelope envelope = new ArrayEnvelope(0);
+        assertTrue(envelope.isAllNaN());
+    }
+
+    /**
+     * Tests {@link ArrayEnvelope#equals(Object)}.
+     */
+    @Test
+    @SuppressWarnings("ObjectEqualsNull")
+    public void testEquals() {
+        ArrayEnvelope env1 = new ArrayEnvelope(new double[] {1, 2, 4, 5});
+        ArrayEnvelope env2 = new ArrayEnvelope(new double[] {3, 2, 4, 5});
+        assertFalse(env1.equals(null));
+        assertFalse(env1.equals(env2));
+        assertFalse(env2.equals(env1));
+        assertTrue (env1.equals(env1));
+        assertTrue (env2.equals(env2));
+
+        env2.ordinates[0] = 1;
+        assertTrue(env1.equals(env2));
+        assertTrue(env2.equals(env1));
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ArrayEnvelopeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ArrayEnvelopeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/CoordinateFormatTest.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -21,6 +21,7 @@ import java.util.Locale;
 import java.util.TimeZone;
 import java.text.ParsePosition;
 import java.text.ParseException;
+import java.io.IOException;
 import org.opengis.geometry.DirectPosition;
 import org.apache.sis.measure.Angle;
 import org.apache.sis.referencing.crs.HardCodedCRS;
@@ -36,6 +37,8 @@ import static org.junit.Assert.*;
  * Tests the {@link CoordinateFormat} class.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @author  Michael Hausegger
+ *
  * @version 0.8
  *
  * @see org.apache.sis.measure.AngleFormatTest
@@ -63,6 +66,7 @@ public final strictfp class CoordinateFo
          * Try again with a different separator.
          */
         format.setSeparator("; ");
+        assertEquals("; ", format.getSeparator());
         assertEquals("4.64; 10.25; -3.12", format.format(position));
     }
 
@@ -75,30 +79,31 @@ public final strictfp class CoordinateFo
     @Test
     public void testParseUnknownCRS() throws ParseException {
         final CoordinateFormat format = new CoordinateFormat(null, null);
-        final ParsePosition index = new ParsePosition(0);
-        DirectPosition position = format.parse("23.78 -12.74 127.9 3.25", index);
+        final ParsePosition charPos = new ParsePosition(0);
+        DirectPosition position = format.parse("23.78 -12.74 127.9 3.25", charPos);
         assertArrayEquals(new double[] {23.78, -12.74, 127.9, 3.25}, position.getCoordinate(),
STRICT);
-        assertEquals("ParsePosition.getErrorIndex()", -1, index.getErrorIndex());
-        assertEquals("ParsePosition.getIndex()",      23, index.getIndex());
+        assertEquals("ParsePosition.getErrorIndex()", -1, charPos.getErrorIndex());
+        assertEquals("ParsePosition.getIndex()",      23, charPos.getIndex());
         /*
          * Try another point having a different number of position
          * for verifying that no cached values are causing problem.
          */
-        index.setIndex(0);
-        position = format.parse("4.64 10.25 -3.12", index);
+        charPos.setIndex(0);
+        position = format.parse("4.64 10.25 -3.12", charPos);
         assertArrayEquals(new double[] {4.64, 10.25, -3.12}, position.getCoordinate(), STRICT);
-        assertEquals("ParsePosition.getErrorIndex()", -1, index.getErrorIndex());
-        assertEquals("ParsePosition.getIndex()",      16, index.getIndex());
+        assertEquals("ParsePosition.getErrorIndex()", -1, charPos.getErrorIndex());
+        assertEquals("ParsePosition.getIndex()",      16, charPos.getIndex());
         /*
          * Try again with a different separator. Also put or remove some spaces
          * around the separator for testing UnitFormat capabilities to ignore them.
          */
         format.setSeparator("; ");
-        index.setIndex(0);
-        position = format.parse("4.64;10.25 ;  -3.12", index);
+        assertEquals("; ", format.getSeparator());
+        charPos.setIndex(0);
+        position = format.parse("4.64;10.25 ;  -3.12", charPos);
         assertArrayEquals(new double[] {4.64, 10.25, -3.12}, position.getCoordinate(), STRICT);
-        assertEquals("ParsePosition.getErrorIndex()", -1, index.getErrorIndex());
-        assertEquals("ParsePosition.getIndex()",      19, index.getIndex());
+        assertEquals("ParsePosition.getErrorIndex()", -1, charPos.getErrorIndex());
+        assertEquals("ParsePosition.getIndex()",      19, charPos.getIndex());
     }
 
     /**
@@ -150,6 +155,7 @@ public final strictfp class CoordinateFo
          * Try again with the original CRS, but different separator.
          */
         format.setSeparator("; ");
+        assertEquals("; ", format.getSeparator());
         position.setCoordinateReferenceSystem(HardCodedCRS.GEOID_4D);
         assertEquals("getPattern(Angle)", anglePattern, format.getPattern(Angle.class));
         assertEquals("getPattern(Date)",   datePattern, format.getPattern(Date .class));
@@ -168,24 +174,97 @@ public final strictfp class CoordinateFo
         final CoordinateFormat format = new CoordinateFormat(Locale.FRANCE, TimeZone.getTimeZone("GMT+01:00"));
         format.applyPattern(Date.class, "dd-MM-yyyy HH:mm");
         format.setDefaultCRS(HardCodedCRS.GEOID_4D);
-        final ParsePosition index = new ParsePosition(11);
-        final DirectPosition pos = format.parse("(to skip); 23°46,8′E 12°44,4′S 127,9 m
22-09-2006 07:00 (ignore)", index);
+        final ParsePosition charPos = new ParsePosition(11);
+        final DirectPosition pos = format.parse("(to skip); 23°46,8′E 12°44,4′S 127,9 m
22-09-2006 07:00 (ignore)", charPos);
         assertArrayEquals(new double[] {23.78, -12.74, 127.90, 54000.25}, pos.getCoordinate(),
STRICT);
-        assertEquals("ParsePosition.getErrorIndex()", -1, index.getErrorIndex());
-        assertEquals("ParsePosition.getIndex()",      55, index.getIndex());
+        assertEquals("ParsePosition.getErrorIndex()", -1, charPos.getErrorIndex());
+        assertEquals("ParsePosition.getIndex()",      55, charPos.getIndex());
         /*
          * Tests error message when parsing the same string but with unknown units of measurement.
          */
-        index.setIndex(11);
+        charPos.setIndex(11);
         try {
-            format.parse("(to skip); 23°46,8′E 12°44,4′S 127,9 Foo 22-09-2006 07:00",
index);
+            format.parse("(to skip); 23°46,8′E 12°44,4′S 127,9 Foo 22-09-2006 07:00",
charPos);
             fail("Should not have parsed a coordinate with unknown units.");
         } catch (ParseException e) {
-            assertEquals("ParsePosition.getIndex()",        11, index.getIndex());
-            assertEquals("ParsePosition.getErrorIndex()",   37, index.getErrorIndex());
+            assertEquals("ParsePosition.getIndex()",        11, charPos.getIndex());
+            assertEquals("ParsePosition.getErrorIndex()",   37, charPos.getErrorIndex());
             assertEquals("ParseException.getErrorOffset()", 37, e.getErrorOffset());
             assertEquals("Les caractères « Foo » après « 23°46,8′E 12°44,4′S
127,9 » sont inattendus.",
                          e.getLocalizedMessage());  // In the language specified at CoordinateFormat
construction time.
         }
     }
+
+    /**
+     * Tests formatting a coordinate in default locale, then parsing the result. This test
verifies that the
+     * parsing is consistent with formatting in whatever locale used by the platform. This
test does not verify
+     * if the formatted string is equal to any expected value since it is locale-dependent.
+     *
+     * @throws IOException    should never happen since we format into a {@link StringBuffer}.
+     * @throws ParseException if {@code CoordinateFormat} fails to parse the value that it
formatted.
+     */
+    @Test
+    public void testParseInDefaultLocale() throws IOException, ParseException {
+        CoordinateFormat format = new CoordinateFormat();
+        StringBuffer     buffer = new StringBuffer();
+        format.format(new DirectPosition2D(-3, 4), buffer);
+
+        ParsePosition  charPos  = new ParsePosition(0);
+        DirectPosition position = format.parse(buffer, charPos);
+        assertEquals("Should have parsed the whole text.", buffer.length(), charPos.getIndex());
+        assertEquals("DirectPosition.getDimension()", 2, position.getDimension());
+        assertArrayEquals(new double[] {-3, 4}, position.getCoordinate(), STRICT);
+    }
+
+    /**
+     * Tests parsing from a position different then the beginning of the string.
+     *
+     * @throws ParseException if the parsing failed.
+     */
+    @Test
+    public void testParseFromOffset() throws ParseException {
+        CoordinateFormat coordinateFormat = new CoordinateFormat(Locale.CANADA, null);
+        coordinateFormat.setDefaultCRS(VerticalCRSMock.BAROMETRIC_HEIGHT);
+        ParsePosition  charPos  = new ParsePosition(7);
+        DirectPosition position = coordinateFormat.parse("[skip] 12", charPos);
+        assertEquals("Should have parsed the whole text.", 9, charPos.getIndex());
+        assertEquals("DirectPosition.getDimension()", 1, position.getDimension());
+        assertArrayEquals(new double[] {12}, position.getCoordinate(), STRICT);
+    }
+
+    /**
+     * Verifies the pattern returned by {@link CoordinateFormat#getPattern(Class)}. This
includes verifying that
+     * the method returns {@code null} when invoked for an unknown type, or a type that does
not support pattern.
+     */
+    @Test
+    public void testGetPattern() {
+        CoordinateFormat coordinateFormat = new CoordinateFormat(Locale.UK, null);
+        assertEquals("#,##0.###", coordinateFormat.getPattern(Byte.class));
+        assertNull(coordinateFormat.getPattern(Object.class));
+        assertNull(coordinateFormat.getPattern(Class.class));
+    }
+
+    /**
+     * Verifies that {@link CoordinateFormat#applyPattern(Class, String)} when
+     * invoked for an unknown type, or for a type that does not support patterns.
+     */
+    @Test
+    public void testApplyPattern() {
+        CoordinateFormat format = new CoordinateFormat();
+        assertFalse(format.applyPattern(Object.class, "A dummy pattern"));
+        assertFalse(format.applyPattern(Class.class,  "A dummy pattern"));
+    }
+
+    /**
+     * Tests {@link CoordinateFormat#clone()}, then verifies that the clone has the same
configuration
+     * than the original object.
+     */
+    @Test
+    public void testClone() {
+        CoordinateFormat format = new CoordinateFormat(Locale.CANADA, null);
+        CoordinateFormat clone  = format.clone();
+        assertNotSame("clone()", clone, format);
+        assertEquals("getSeparator()",  format.getSeparator(),  clone.getSeparator());
+        assertEquals("getDefaultCRS()", format.getDefaultCRS(), clone.getDefaultCRS());
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -43,7 +43,7 @@ import static org.apache.sis.geometry.Ab
  * @since   0.3
  * @module
  */
-@DependsOn(AbstractEnvelopeTest.class)
+@DependsOn(ArrayEnvelopeTest.class)
 public strictfp class GeneralEnvelopeTest extends TestCase {
     /**
      * Tolerance threshold for floating point comparisons.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ImmutableEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ImmutableEnvelopeTest.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ImmutableEnvelopeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/ImmutableEnvelopeTest.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -35,7 +35,7 @@ import static org.apache.sis.geometry.Ab
  * @since   0.3
  * @module
  */
-@DependsOn(AbstractEnvelopeTest.class)
+@DependsOn(ArrayEnvelopeTest.class)
 public final strictfp class ImmutableEnvelopeTest extends TestCase {
     /**
      * Tests {@code ImmutableEnvelope} serialization.

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1809632&r1=1809631&r2=1809632&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Mon Sep 25 14:09:04 2017
@@ -234,6 +234,7 @@ import org.junit.BeforeClass;
     org.apache.sis.geometry.DirectPosition1DTest.class,
     org.apache.sis.geometry.DirectPosition2DTest.class,
     org.apache.sis.geometry.AbstractEnvelopeTest.class,
+    org.apache.sis.geometry.ArrayEnvelopeTest.class,
     org.apache.sis.geometry.GeneralEnvelopeTest.class,
     org.apache.sis.geometry.SubEnvelopeTest.class,
     org.apache.sis.geometry.ImmutableEnvelopeTest.class,



Mime
View raw message