sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1596663 - in /sis/branches/JDK8/core: sis-feature/src/main/java/org/apache/sis/feature/ sis-feature/src/test/java/org/apache/sis/feature/ sis-feature/src/test/java/org/apache/sis/test/suite/ sis-utility/src/main/java/org/apache/sis/util/re...
Date Wed, 21 May 2014 19:51:19 GMT
Author: desruisseaux
Date: Wed May 21 19:51:18 2014
New Revision: 1596663

URL: http://svn.apache.org/r1596663
Log:
Added tests.

Added:
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java?rev=1596663&r1=1596662&r2=1596663&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
[UTF-8] Wed May 21 19:51:18 2014
@@ -37,7 +37,7 @@ public final class Features extends Stat
 
     /**
      * Casts the given attribute type to the given parameterized type.
-     * An exception is thrown immediately if the type does not have the expected
+     * An exception is thrown immediately if the given type does not have the expected
      * {@linkplain DefaultAttributeType#getValueClass() value class}.
      *
      * @param  <T>        The expected value class.
@@ -57,9 +57,39 @@ public final class Features extends Stat
             // We require a strict equality - not type.isAssignableFrom(actual) - because
in
             // the later case we could have (to be strict) to return a <? extends T>
type.
             if (!valueClass.equals(actual)) {
-                throw new ClassCastException(Errors.format(Errors.Keys.MismatchedPropertyType_1,
type.getName()));
+                throw new ClassCastException(Errors.format(Errors.Keys.MismatchedValueClass_3,
+                        type.getName(), valueClass, actual));
             }
         }
         return (DefaultAttributeType<T>) type;
     }
+
+    /**
+     * Casts the given attribute instance to the given parameterized type.
+     * An exception is thrown immediately if the given instance does not have the expected
+     * {@linkplain DefaultAttributeType#getValueClass() value class}.
+     *
+     * @param  <T>        The expected value class.
+     * @param  attribute  The attribute instance to cast, or {@code null}.
+     * @param  valueClass The expected value class.
+     * @return The attribute instance casted to the given value class, or {@code null} if
the given instance was null.
+     * @throws ClassCastException if the given attribute instance does not have the expected
value class.
+     *
+     * @category verification
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> DefaultAttribute<T> cast(final DefaultAttribute<?>
attribute, final Class<T> valueClass)
+            throws ClassCastException
+    {
+        if (attribute != null) {
+            final Class<?> actual = attribute.getType().getValueClass();
+            // We require a strict equality - not type.isAssignableFrom(actual) - because
in
+            // the later case we could have (to be strict) to return a <? extends T>
type.
+            if (!valueClass.equals(actual)) {
+                throw new ClassCastException(Errors.format(Errors.Keys.MismatchedValueClass_3,
+                        attribute.getName(), valueClass, actual));
+            }
+        }
+        return (DefaultAttribute<T>) attribute;
+    }
 }

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java?rev=1596663&r1=1596662&r2=1596663&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java
[UTF-8] Wed May 21 19:51:18 2014
@@ -32,14 +32,14 @@ import static java.util.Collections.sing
 
 
 /**
- * Base class of {@link DenseFeatureTest} and {@link SparseFeatureTest}.
+ * Tests common to {@link DenseFeatureTest} and {@link SparseFeatureTest}.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
  * @version 0.5
  * @module
  */
-abstract strictfp class FeatureTestCase extends TestCase {
+public abstract strictfp class FeatureTestCase extends TestCase {
     /**
      * The feature being tested.
      */

Added: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java?rev=1596663&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeaturesTest.java
[UTF-8] Wed May 21 19:51:18 2014
@@ -0,0 +1,71 @@
+/*
+ * 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;
+
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link Features}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+@DependsOn(DefaultAttributeTest.class)
+public final strictfp class FeaturesTest extends TestCase {
+    /**
+     * Tests {@link Features#cast(AttributeType, Class)}.
+     */
+    @Test
+    public void testCastAttributeType() {
+        final DefaultAttributeType<String> parliament = DefaultAttributeTypeTest.parliament();
+        assertSame(parliament, Features.cast(parliament, String.class));
+        try {
+            Features.cast(parliament, CharSequence.class);
+            fail("Shall not be allowed to cast to a different type.");
+        } catch (ClassCastException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("parliament"));
+            assertTrue(message, message.contains("String"));
+            assertTrue(message, message.contains("CharSequence"));
+        }
+    }
+
+    /**
+     * Tests {@link Features#cast(Attribute, Class)}.
+     */
+    @Test
+    public void testCastAttributeInstance() {
+        final DefaultAttribute<String> parliament = DefaultAttributeTest.parliament();
+        assertSame(parliament, Features.cast(parliament, String.class));
+        try {
+            Features.cast(parliament, CharSequence.class);
+            fail("Shall not be allowed to cast to a different type.");
+        } catch (ClassCastException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("parliament"));
+            assertTrue(message, message.contains("String"));
+            assertTrue(message, message.contains("CharSequence"));
+        }
+    }
+}

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

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

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=1596663&r1=1596662&r2=1596663&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] Wed May 21 19:51:18 2014
@@ -39,7 +39,8 @@ import org.junit.BeforeClass;
     org.apache.sis.feature.DefaultAssociationRoleTest.class,
     org.apache.sis.feature.DefaultAssociationTest.class,
     org.apache.sis.feature.DefaultOperationTest.class,
-    org.apache.sis.feature.FeatureFormatTest.class
+    org.apache.sis.feature.FeatureFormatTest.class,
+    org.apache.sis.feature.FeaturesTest.class
 })
 public final strictfp class FeatureTestSuite extends TestSuite {
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1596663&r1=1596662&r2=1596663&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Wed May 21 19:51:18 2014
@@ -433,6 +433,11 @@ public final class Errors extends Indexe
         public static final short MismatchedPropertyType_1 = 154;
 
         /**
+         * Class of “{0}” values is ‘{2}’, but the requested type is ‘{1}’.
+         */
+        public static final short MismatchedValueClass_3 = 157;
+
+        /**
          * No authority was specified for code “{0}”. The expected syntax is “AUTHORITY:CODE”.
          */
         public static final short MissingAuthority_1 = 135;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1596663&r1=1596662&r2=1596663&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Wed May 21 19:51:18 2014
@@ -97,6 +97,7 @@ MismatchedDimension_3             = Argu
 MismatchedMatrixSize_4            = Mismatched matrix sizes: expected {0}\u00d7{1} but got
{2}\u00d7{3}.
 MismatchedParameterDescriptor_1   = Mismatched descriptor for \u201c{0}\u201d parameter.
 MismatchedPropertyType_1          = Mismatched type for \u201c{0}\u201d property.
+MismatchedValueClass_3            = Class of \u201c{0}\u201d values is \u2018{2}\u2019, but
the requested type is \u2018{1}\u2019.
 MissingAuthority_1                = No authority was specified for code \u201c{0}\u201d.
The expected syntax is \u201cAUTHORITY:CODE\u201d.
 MissingRequiredModule_1           = This operation requires the \u201c{0}\u201d module.
 MissingSchemeInURI                = Missing scheme in URI.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1596663&r1=1596662&r2=1596663&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Wed May 21 19:51:18 2014
@@ -87,6 +87,7 @@ MismatchedDimension_3             = L\u2
 MismatchedMatrixSize_4            = Une matrice de taille de {0}\u00d7{1} \u00e9tait attendue
mais la matrice donn\u00e9es est de taille {2}\u00d7{3}.
 MismatchedParameterDescriptor_1   = Le descripteur du param\u00e8tre \u00ab\u202f{0}\u202f\u00bb
ne correspond pas.
 MismatchedPropertyType_1          = Le type de la propri\u00e9t\u00e9 \u00ab\u202f{0}\u202f\u00bb
ne correspond pas.
+MismatchedValueClass_3            = Les valeurs de \u00ab\u202f{0}\u202f\u00bb sont de la
classe \u2018{2}\u2019, alors que le type demand\u00e9 \u00e9tait \u2018{1}\u2019.
 MissingAuthority_1                = Aucune autorit\u00e9 n\u2019a \u00e9t\u00e9 sp\u00e9cifi\u00e9e
pour le code \u00ab\u202f{0}\u202f\u00bb. Le format attendu est \u00ab\u202fAUTORIT\u00c9:CODE\u202f\u00bb.
 MissingRequiredModule_1           = Cette op\u00e9ration requiert le module \u00ab\u202f{0}\u202f\u00bb.
 MissingSchemeInURI                = Il manque le sch\u00e9ma d\u2019URI.



Mime
View raw message