sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1755221 - in /sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature: DefaultFeatureTypeTest.java FeatureTestCase.java
Date Thu, 04 Aug 2016 17:33:25 GMT
Author: desruisseaux
Date: Thu Aug  4 17:33:25 2016
New Revision: 1755221

URL: http://svn.apache.org/viewvc?rev=1755221&view=rev
Log:
Add a test about multi-valued properties.

Modified:
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureTestCase.java

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java?rev=1755221&r1=1755220&r2=1755221&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java
[UTF-8] Thu Aug  4 17:33:25 2016
@@ -34,6 +34,7 @@ import static org.apache.sis.test.TestUt
 
 // Branch-dependent imports
 import org.opengis.feature.PropertyType;
+import org.opengis.feature.AttributeType;
 
 
 /**
@@ -41,7 +42,7 @@ import org.opengis.feature.PropertyType;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.6
+ * @version 0.8
  * @module
  */
 @DependsOn(DefaultAttributeTypeTest.class)
@@ -308,8 +309,8 @@ public final strictfp class DefaultFeatu
 
         final Map<String,String> identification = singletonMap(DefaultAttributeType.NAME_KEY,
"City");
         try {
-            new DefaultFeatureType(identification, false, null, city, population, cityId);
-            fail("Duplicated attribute names shall not be allowed.");
+            final Object t = new DefaultFeatureType(identification, false, null, city, population,
cityId);
+            fail("Duplicated attribute names shall not be allowed:\n" + t);
         } catch (IllegalArgumentException e) {
             final String message = e.getMessage();
             assertTrue(message, message.contains("name"));      // Property name.
@@ -416,7 +417,7 @@ public final strictfp class DefaultFeatu
         assertPropertiesEquals(metroCapital, false, "country");
         assertPropertiesEquals(metroCapital, true, "city", "population", "region", "isGlobal",
"parliament", "country");
         assertEquals("property(“region”).valueClass", CharSequence.class,
-                ((DefaultAttributeType) metroCapital.getProperty("region")).getValueClass());
+                ((AttributeType<?>) metroCapital.getProperty("region")).getValueClass());
 
         // Check based only on name.
         assertTrue ("maybeAssignableFrom", DefaultFeatureType.maybeAssignableFrom(capital,
metroCapital));
@@ -460,7 +461,7 @@ public final strictfp class DefaultFeatu
         assertPropertiesEquals(worldMetropolis, false, "region", "temperature");
         assertPropertiesEquals(worldMetropolis, true, "city", "population", "region", "isGlobal",
"universities", "temperature");
         assertEquals("property(“region”).valueClass", InternationalString.class,
-                ((DefaultAttributeType) worldMetropolis.getProperty("region")).getValueClass());
+                ((AttributeType<?>) worldMetropolis.getProperty("region")).getValueClass());
 
         // Check based only on name.
         assertTrue ("maybeAssignableFrom", DefaultFeatureType.maybeAssignableFrom(metropolis,
worldMetropolis));

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=1755221&r1=1755220&r2=1755221&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] Thu Aug  4 17:33:25 2016
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.feature;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import org.opengis.metadata.quality.DataQuality;
@@ -33,6 +34,7 @@ import static org.apache.sis.test.Assert
 
 // Branch-dependent imports
 import org.opengis.feature.Attribute;
+import org.opengis.feature.AttributeType;
 import org.opengis.feature.Property;
 
 
@@ -307,7 +309,7 @@ public abstract strictfp class FeatureTe
         feature = createFeature(DefaultFeatureTypeTest.city());
         final AbstractAttribute<String> wrong = SingletonAttributeTest.parliament();
         final CustomAttribute<String> city = new CustomAttribute<>(Features.cast(
-                (DefaultAttributeType<?>) feature.getType().getProperty("city"), String.class));
+                (AttributeType<?>) feature.getType().getProperty("city"), String.class));
 
         feature.setProperty(city);
         setAttributeValue("city", "Utopia", "Atlantide");
@@ -341,6 +343,26 @@ public abstract strictfp class FeatureTe
     }
 
     /**
+     * Tests addition of values in a multi-valued property.
+     */
+    @Test
+    @DependsOnMethod("testSimpleProperties")
+    public void testAddToCollection() {
+        feature = createFeature(new DefaultFeatureType(
+                Collections.singletonMap(DefaultFeatureType.NAME_KEY, "City"),
+                false, null, DefaultAttributeTypeTest.universities()));
+
+        feature.setPropertyValue("universities", Arrays.asList("UCAR", "Marie-Curie"));
+        /*
+         * The value below is an instance of Collection<String>. But as of Java 8,
the <String> parameterized type
+         * can not be verified at runtime. The best check we can have is Collection<?>,
which does not allow addition
+         * of new values.
+         */
+        final Collection<?> values = (Collection<?>) feature.getPropertyValue("universities");
+        assertArrayEquals(new String[] {"UCAR", "Marie-Curie"}, values.toArray());
+    }
+
+    /**
      * Asserts that {@link AbstractFeature#quality()} reports no anomaly, or only anomalies
for the given properties.
      *
      * @param  anomalousProperties  the property for which we expect a report.



Mime
View raw message