sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1422244 - in /sis/branches/JDK7: ./ sis-referencing/ sis-referencing/src/main/java/org/apache/sis/geometry/ sis-referencing/src/test/java/org/apache/sis/geometry/
Date Sat, 15 Dec 2012 13:11:21 GMT
Author: desruisseaux
Date: Sat Dec 15 13:11:19 2012
New Revision: 1422244

URL: http://svn.apache.org/viewvc?rev=1422244&view=rev
Log:
Added tests for DirectPosition implementations.

Added:
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition1DTest.java
  (with props)
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition2DTest.java
  (with props)
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
  (with props)
Modified:
    sis/branches/JDK7/pom.xml
    sis/branches/JDK7/sis-referencing/pom.xml
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java

Modified: sis/branches/JDK7/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/pom.xml?rev=1422244&r1=1422243&r2=1422244&view=diff
==============================================================================
--- sis/branches/JDK7/pom.xml (original)
+++ sis/branches/JDK7/pom.xml Sat Dec 15 13:11:19 2012
@@ -341,6 +341,13 @@ Apache SIS is a toolkit for describing l
             </manifestEntries>
           </archive>
         </configuration>
+        <executions>
+         <execution>
+           <goals>
+             <goal>test-jar</goal>
+           </goals>
+         </execution>
+       </executions>
       </plugin>
 
       <!-- Package as OSGi bundle -->

Modified: sis/branches/JDK7/sis-referencing/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/pom.xml?rev=1422244&r1=1422243&r2=1422244&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/pom.xml (original)
+++ sis/branches/JDK7/sis-referencing/pom.xml Sat Dec 15 13:11:19 2012
@@ -62,6 +62,15 @@
       <groupId>org.geonames</groupId>
       <artifactId>georss-rome</artifactId>
     </dependency>
+
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.apache.sis</groupId>
+      <artifactId>sis-utility</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java?rev=1422244&r1=1422243&r2=1422244&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
Sat Dec 15 13:11:19 2012
@@ -213,6 +213,7 @@ public abstract class AbstractDirectPosi
          */
         if (c == '(' || c == '[') {
             i += Character.charCount(c);
+            i = CharSequences.skipLeadingWhitespaces(wkt, i, length);
             final char close = (c == '(') ? ')' : ']';
             final int pos = CharSequences.lastIndexOf(wkt, close, i, length);
             if (pos != --length) {
@@ -223,10 +224,11 @@ public abstract class AbstractDirectPosi
                     args = new Object[] {wkt, close};
                 } else {
                     key  = Errors.Keys.UnparsableStringForClass_3;
-                    args = new Object[] {"POINT", wkt, wkt.subSequence(pos+1, length+1)};
+                    args = new Object[] {"POINT", wkt, CharSequences.trimWhitespaces(wkt,
pos+1, length+1)};
                 }
                 throw new IllegalArgumentException(Errors.format(key, args));
             }
+            c = Character.codePointAt(wkt, i);
         }
         /*
          * Index i is either at the beginning of a number or at the closing parenthesis.

Added: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition1DTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition1DTest.java?rev=1422244&view=auto
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition1DTest.java
(added)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition1DTest.java
Sat Dec 15 13:11:19 2012
@@ -0,0 +1,82 @@
+/*
+ * 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.opengis.geometry.DirectPosition;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests the {@link DirectPosition1D} class.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(GeneralDirectPositionTest.class)
+public final strictfp class DirectPosition1DTest extends TestCase {
+    /**
+     * Tests the {@link DirectPosition1D#toString()} method.
+     */
+    @Test
+    public void testWktFormatting() {
+        assertEquals("POINT(8.5)", new DirectPosition1D(8.5).toString());
+    }
+
+    /**
+     * Tests the {@link DirectPosition1D#DirectPosition2D(String)} constructor.
+     */
+    @Test
+    public void testWktParsing() {
+        assertEquals("POINT(8)", new DirectPosition1D("POINT(8)").toString());
+    }
+
+    /**
+     * Tests {@link DirectPosition2D#equals(Object)} method between different implementations.
+     * The purpose of this test is also to run the assertion in the direct position implementations.
+     */
+    @Test
+    public void testEquals() {
+        assertTrue(DirectPosition1D     .class.desiredAssertionStatus());
+        assertTrue(GeneralDirectPosition.class.desiredAssertionStatus());
+
+        DirectPosition p1 = new DirectPosition1D     (48.543261561072285);
+        DirectPosition p2 = new GeneralDirectPosition(48.543261561072285);
+        assertTrue(p1.equals(p2));
+        assertTrue(p2.equals(p1));
+
+        p1.setOrdinate(0, p1.getOrdinate(0) + 1);
+        assertFalse(p1.equals(p2));
+        assertFalse(p2.equals(p1));
+    }
+
+    /**
+     * Tests {@link DirectPosition1D#clone()}.
+     */
+    @Test
+    public void testClone() {
+        final DirectPosition1D p1 = new DirectPosition1D(20);
+        final DirectPosition1D p2 = p1.clone();
+        assertEquals("Expected the same CRS and ordinates.", p1, p2);
+        assertEquals("Expected the same ordinates.", 20.0, p2.ordinate, 0.0);
+    }
+}

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition1DTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition1DTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition2DTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition2DTest.java?rev=1422244&view=auto
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition2DTest.java
(added)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition2DTest.java
Sat Dec 15 13:11:19 2012
@@ -0,0 +1,83 @@
+/*
+ * 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.opengis.geometry.DirectPosition;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests the {@link DirectPosition2D} class.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(GeneralDirectPositionTest.class)
+public final strictfp class DirectPosition2DTest extends TestCase {
+    /**
+     * Tests the {@link DirectPosition2D#toString()} method.
+     */
+    @Test
+    public void testWktFormatting() {
+        assertEquals("POINT(6.5 10)", new DirectPosition2D(6.5, 10).toString());
+    }
+
+    /**
+     * Tests the {@link DirectPosition2D#DirectPosition2D(String)} constructor.
+     */
+    @Test
+    public void testWktParsing() {
+        assertEquals("POINT(6 10)", new DirectPosition2D("POINT(6 10)").toString());
+    }
+
+    /**
+     * Tests {@link DirectPosition2D#equals(Object)} method between different implementations.
+     * The purpose of this test is also to run the assertion in the direct position implementations.
+     */
+    @Test
+    public void testEquals() {
+        assertTrue(DirectPosition2D     .class.desiredAssertionStatus());
+        assertTrue(GeneralDirectPosition.class.desiredAssertionStatus());
+
+        DirectPosition p1 = new DirectPosition2D     (48.543261561072285, -123.47009555832284);
+        DirectPosition p2 = new GeneralDirectPosition(48.543261561072285, -123.47009555832284);
+        assertTrue(p1.equals(p2));
+        assertTrue(p2.equals(p1));
+
+        p1.setOrdinate(0, p1.getOrdinate(0) + 1);
+        assertFalse(p1.equals(p2));
+        assertFalse(p2.equals(p1));
+    }
+
+    /**
+     * Tests {@link DirectPosition2D#clone()}.
+     */
+    @Test
+    public void testClone() {
+        final DirectPosition2D p1 = new DirectPosition2D(10, 30);
+        final DirectPosition2D p2 = p1.clone();
+        assertEquals("Expected the same CRS and ordinates.", p1, p2);
+        assertEquals("Expected the same ordinates.", 10.0, p2.x, 0.0);
+        assertEquals("Expected the same ordinates.", 30.0, p2.y, 0.0);
+    }
+}

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition2DTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/DirectPosition2DTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java?rev=1422244&view=auto
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
(added)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
Sat Dec 15 13:11:19 2012
@@ -0,0 +1,98 @@
+/*
+ * 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 java.util.Arrays;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests the {@link GeneralDirectPosition} class.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class GeneralDirectPositionTest extends TestCase {
+    /**
+     * Tests the {@link GeneralDirectPosition#toString()} method.
+     */
+    @Test
+    public void testWktFormatting() {
+        assertEquals("POINT(6 10 2)", new GeneralDirectPosition(6, 10, 2).toString());
+    }
+
+    /**
+     * Tests the {@link GeneralDirectPosition#GeneralDirectPosition(String)} constructor.
+     */
+    @Test
+    public void testWktParsing() {
+        assertEquals("POINT(6 10 2)", new GeneralDirectPosition("POINT(6 10 2)").toString());
+        assertEquals("POINT(3 14 2)", new GeneralDirectPosition("POINT M [ 3 14 2 ] ").toString());
+        assertEquals("POINT(2 10 8)", new GeneralDirectPosition("POINT Z 2 10 8").toString());
+        assertEquals("POINT()",       new GeneralDirectPosition("POINT()").toString());
+        assertEquals("POINT()",       new GeneralDirectPosition("POINT ( ) ").toString());
+    }
+
+    /**
+     * Tests the {@link GeneralDirectPosition#GeneralDirectPosition(String)} constructor
+     * with invalid input strings.
+     */
+    @Test
+    public void testWktParsingFailures() {
+        try {
+            new GeneralDirectPosition("POINT(6 10 2");
+            fail("Parsing should fails because of missing parenthesis.");
+        } catch (IllegalArgumentException e) {
+            // This is the expected exception.
+            final String message = e.getMessage();
+            assertTrue(message.contains("POINT(6 10 2"));
+            assertTrue(message.contains("‘)’"));
+        }
+        try {
+            new GeneralDirectPosition("POINT 6 10 2)");
+            fail("Parsing should fails because of missing parenthesis.");
+        } catch (IllegalArgumentException e) {
+            // This is the expected exception.
+        }
+        try {
+            new GeneralDirectPosition("POINT(6 10 2) x");
+            fail("Parsing should fails because of extra characters.");
+        } catch (IllegalArgumentException e) {
+            // This is the expected exception.
+            final String message = e.getMessage();
+            assertTrue(message.contains("POINT(6 10 2) x"));
+            assertTrue(message.contains("“x”"));
+        }
+    }
+
+    /**
+     * Tests {@link GeneralDirectPosition#clone()}.
+     */
+    @Test
+    public void testClone() {
+        final GeneralDirectPosition p1 = new GeneralDirectPosition(10, 20, 30);
+        final GeneralDirectPosition p2 = p1.clone();
+        assertEquals ("Expected the same CRS and ordinates.", p1, p2);
+        assertTrue   ("Expected the same ordinates.", Arrays.equals(p1.ordinates, p2.ordinates));
+        assertNotSame("the ordinates array should have been cloned.", p1.ordinates, p2.ordinates);
+    }
+}

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message