Author: desruisseaux
Date: Mon Dec 10 07:50:34 2012
New Revision: 1419251
URL: http://svn.apache.org/viewvc?rev=1419251&view=rev
Log:
Replaced some AssertionError by ConcurrentModificationException since those
errors could happen if another thread modifes concurrently the collection given
in argument to a method.
Added:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/AbstractNameTest.java
(with props)
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/GeoapiTest.java
(with props)
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultLocalName.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultScopedName.java
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1419251&r1=1419250&r2=1419251&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
Mon Dec 10 07:50:34 2012
@@ -271,6 +271,11 @@ public final class Errors extends Indexe
public static final int UnexpectedArgumentDimension_3 = 5;
/**
+ * Unexpected change in â{0}â.
+ */
+ public static final int UnexpectedChange_1 = 56;
+
+ /**
* More characters were expected at the end of â{0}â.
*/
public static final int UnexpectedEndOfString_1 = 30;
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1419251&r1=1419250&r2=1419251&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
Mon Dec 10 07:50:34 2012
@@ -57,6 +57,7 @@ NullArgument_1 = Argume
RecursiveCreateCallForKey_1 = Recursive call while creating an object for
the \u201c{0}\u201d key.
RequireDecimalSeparator = A decimal separator is required.
UnexpectedArgumentDimension_3 = Argument \u2018{0}\u2019 has {1} dimensions,
while {2} was expected.
+UnexpectedChange_1 = Unexpected change in \u2018{0}\u2019.
UnexpectedEndOfString_1 = More characters were expected at the end of
\u201c{0}\u201d.
UnmodifiableAffineTransform = This affine transform is unmodifiable.
UnmodifiableGeometry = This geometry is unmodifiable.
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1419251&r1=1419250&r2=1419251&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
Mon Dec 10 07:50:34 2012
@@ -57,6 +57,7 @@ NullArgument_1 = L\u201
RecursiveCreateCallForKey_1 = Appel r\u00e9cursif lors de la cr\u00e9ation
d\u2019un objet pour la cl\u00e9 \u201c{0}\u201d.
RequireDecimalSeparator = Un s\u00e9parateur d\u00e9cimal est requis.
UnexpectedArgumentDimension_3 = L\u2019argument \u2018{0}\u2019 a {1}
dimensions, alors qu\u2019on en attendait {2}.
+UnexpectedChange_1 = Changement inattendu dans \u2018{0}\u2019.
UnexpectedEndOfString_1 = D\u2019autres caract\u00e8res \u00e9taient
attendus \u00e0 la fin du texte \u201c{0}\u201d.
UnmodifiableAffineTransform = Cette transformation affine n\u2019est pas
modifiable.
UnmodifiableGeometry = Cette g\u00e9om\u00e9trie n\u2019est pas
modifiable.
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultLocalName.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultLocalName.java?rev=1419251&r1=1419250&r2=1419251&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultLocalName.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultLocalName.java
Mon Dec 10 07:50:34 2012
@@ -194,7 +194,7 @@ public class DefaultLocalName extends Ab
}
/**
- * Returns a local-dependent string representation of this locale name.
+ * Returns a local-dependent string representation of this local name.
*/
@Override
public synchronized InternationalString toInternationalString() {
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultScopedName.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultScopedName.java?rev=1419251&r1=1419250&r2=1419251&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultScopedName.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/DefaultScopedName.java
Mon Dec 10 07:50:34 2012
@@ -18,6 +18,7 @@ package org.apache.sis.util.type;
import java.util.List;
import java.util.Iterator;
+import java.util.ConcurrentModificationException;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import net.jcip.annotations.Immutable;
@@ -142,7 +143,9 @@ public class DefaultScopedName extends A
tip.fullyQualified = fullyQualified = this;
}
locals[i++] = tip;
- assert (i == size); // Paranoiac check.
+ if (i != size) { // Paranoiac check.
+ throw new
ConcurrentModificationException(Errors.format(Errors.Keys.UnexpectedChange_1,
"names"));
+ }
parsedNames = UnmodifiableArrayList.wrap(locals);
}
@@ -204,7 +207,9 @@ public class DefaultScopedName extends A
name = it.next();
}
}
- assert (index == locals.length); // Paranoiac check.
+ if (index != locals.length) { // Paranoiac check.
+ throw new
ConcurrentModificationException(Errors.format(Errors.Keys.UnexpectedChange_1,
"tail"));
+ }
parsedNames = UnmodifiableArrayList.wrap(locals);
if (tail instanceof LocalName) {
this.path = path;
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1419251&r1=1419250&r2=1419251&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
(original)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
Mon Dec 10 07:50:34 2012
@@ -62,6 +62,8 @@ import org.junit.runners.Suite;
org.apache.sis.util.type.SimpleInternationalStringTest.class,
org.apache.sis.util.type.DefaultInternationalStringTest.class,
org.apache.sis.internal.util.LocalizedParseExceptionTest.class,
+ org.apache.sis.util.type.AbstractNameTest.class,
+ org.apache.sis.util.type.GeoapiTest.class,
// Measurements and formatting.
org.apache.sis.measure.UnitsTest.class,
Added:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/AbstractNameTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/AbstractNameTest.java?rev=1419251&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/AbstractNameTest.java
(added)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/AbstractNameTest.java
Mon Dec 10 07:50:34 2012
@@ -0,0 +1,112 @@
+/*
+ * 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.util.type;
+
+import java.util.Arrays;
+import org.opengis.util.GenericName;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+import static org.opengis.test.Validators.*;
+import static
org.apache.sis.util.type.DefaultNameSpace.DEFAULT_SEPARATOR_STRING;
+
+
+/**
+ * Tests the {@link DefaultLocalName} and {@link DefaultScopedName}
implementations.
+ * This test suite instantiate the objects directly, without using {@link
DefaultNameFactory}.
+ * For tests using the name factory, see {@link NameFactoryTest}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from goetk-3.00)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class AbstractNameTest extends TestCase {
+ /**
+ * Tests the creation of a local name in the global namespace.
+ * The fully qualified name is {@code "EPSG"}.
+ */
+ @Test
+ public void testGlobalNamespace() {
+ final String EPSG = "EPSG";
+ final DefaultLocalName name = new DefaultLocalName(null, EPSG);
+ assertSame(EPSG, name.toString());
+ assertSame(EPSG, name.toInternationalString().toString());
+ assertSame(GlobalNameSpace.GLOBAL, name.scope());
+ assertNotSame(name, assertSerializedEquals(name));
+ validate(name); // GeoAPI tests.
+ }
+
+ /**
+ * Tests the creation of a local name in a new namespace.
+ * The fully qualified name is {@code "EPSG:4326"}.
+ * The tail and the tip are both local names.
+ */
+ @Test
+ public void testEpsgNamespace() {
+ final String EPSG = "EPSG";
+ final DefaultNameSpace ns = DefaultNameSpace.forName(new
DefaultLocalName(null, EPSG),
+ DEFAULT_SEPARATOR_STRING, DEFAULT_SEPARATOR_STRING);
+ assertSame(EPSG, ns.name().toString());
+ validate(ns); // GeoAPI tests.
+
+ final String WGS84 = "4326";
+ final DefaultLocalName name = new DefaultLocalName(ns, WGS84);
+ assertSame(ns, name.scope());
+ assertSame(WGS84, name.toString());
+ assertEquals(EPSG + ':' + WGS84,
name.toFullyQualifiedName().toString());
+ assertNotSame(name, assertSerializedEquals(name));
+ validate(name); // GeoAPI tests.
+ }
+
+ /**
+ * Tests the creation of a scoped name in a new namespace.
+ * The fully qualified name is {@code "urn:ogc:def:crs:epsg:4326"}.
+ */
+ @Test
+ public void testUrnNamespace() {
+ final String[] parsed = new String[] {
+ "urn","ogc","def","crs","epsg","4326"
+ };
+ GenericName name = new DefaultScopedName(null, Arrays.asList(parsed));
+ assertSame(name, name.toFullyQualifiedName());
+ assertEquals("urn:ogc:def:crs:epsg:4326", name.toString());
+ assertNotSame(name, assertSerializedEquals(name));
+ validate(name); // GeoAPI tests.
+ for (int i=parsed.length; --i>=0;) {
+ name = name.tip();
+ validate(name);
+ assertSame(parsed[i], name.toString());
+ name = name.scope().name();
+ }
+ }
+
+ /**
+ * Tests navigation in a name parsed from a string.
+ */
+ @Test
+ public void testNavigating() {
+ final DefaultNameFactory factory = new DefaultNameFactory();
+ final GenericName name = factory.parseGenericName(null,
"codespace:subspace:name");
+ assertEquals("codespace:subspace:name", name.toString());
+ assertEquals("codespace:subspace",
name.tip().scope().name().toString());
+ assertEquals("codespace",
name.tip().scope().name().tip().scope().name().toString());
+ assertSame(name, name.toFullyQualifiedName());
+ assertSame(name, name.tip().toFullyQualifiedName());
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/AbstractNameTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/AbstractNameTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/GeoapiTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/GeoapiTest.java?rev=1419251&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/GeoapiTest.java
(added)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/GeoapiTest.java
Mon Dec 10 07:50:34 2012
@@ -0,0 +1,66 @@
+/*
+ * 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.util.type;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.opengis.test.util.NameTest;
+import org.apache.sis.test.DependsOn;
+
+
+/**
+ * Runs the suite of tests provided in the GeoAPI project. The test suite is
run using
+ * a {@link DefaultNameFactory} instance shared for all tests in this class.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from goetk-3.00)
+ * @version 0.3
+ * @module
+ */
+@RunWith(JUnit4.class)
+@DependsOn(AbstractNameTest.class)
+public final strictfp class GeoapiTest extends NameTest {
+ /**
+ * The factory to test.
+ */
+ private static DefaultNameFactory factory;
+
+ /**
+ * Creates a new test suite using the singleton factory instance.
+ */
+ public GeoapiTest() {
+ super(factory);
+ }
+
+ /**
+ * Creates the singleton factory instance to be reused for all tests in
this class.
+ */
+ @BeforeClass
+ public static void createFactory() {
+ factory = new DefaultNameFactory();
+ }
+
+ /**
+ * Disposes the singleton factory instance after all tests have been
executed.
+ */
+ @AfterClass
+ public static void disposeFactory() {
+ factory = null;
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/GeoapiTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/util/type/GeoapiTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain