sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1594624 - in /sis/branches/JDK8/core/sis-feature/src: main/java/org/apache/sis/feature/ test/java/org/apache/sis/feature/
Date Wed, 14 May 2014 15:54:34 GMT
Author: desruisseaux
Date: Wed May 14 15:54:33 2014
New Revision: 1594624

URL: http://svn.apache.org/r1594624
Log:
Added more tests.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTypeTest.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java?rev=1594624&r1=1594623&r2=1594624&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/DefaultFeatureType.java
[UTF-8] Wed May 14 15:54:33 2014
@@ -16,14 +16,15 @@
  */
 package org.apache.sis.feature;
 
-import java.util.Map;
-import java.util.Set;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.IdentityHashMap;
-import java.util.HashSet;
-import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -55,7 +56,7 @@ import org.apache.sis.internal.util.Unmo
  * Names can be {@linkplain org.apache.sis.util.iso.DefaultScopedName scoped} for avoiding
name collision.
  *
  * {@section Properties and inheritance}
- * Each feature type can provide descriptions for the following {@linkplain #properties()
properties}:
+ * Each feature type can provide descriptions for the following {@linkplain #properties(boolean)
properties}:
  *
  * <ul>
  *   <li>{@linkplain DefaultAttributeType    Attributes}</li>
@@ -205,28 +206,15 @@ public class DefaultFeatureType extends 
     }
 
     /**
-     * Returns the string representation of the given name, making sure that the name is
non-null
-     * and the string non-empty. This method is used for checking argument validity.
+     * Invoked on deserialization for restoring the {@link #byName} and other transient fields.
      *
-     * @param name   The name for which to get the string representation.
-     * @param source The feature which contains the property (typically {@code this}).
-     * @param index  Index of the property having the given name.
+     * @param  in The input stream from which to deserialize a feature type.
+     * @throws IOException If an I/O error occurred while reading or if the stream contains
invalid data.
+     * @throws ClassNotFoundException If the class serialized on the stream is not on the
classpath.
      */
-    private String toString(final GenericName name, final DefaultFeatureType source, final
int index) {
-        short key = Errors.Keys.MissingValueForProperty_1;
-        if (name != null) {
-            final String s = name.toString();
-            if (!s.isEmpty()) {
-                return s;
-            }
-            key = Errors.Keys.EmptyProperty_1;
-        }
-        final StringBuilder b = new StringBuilder(30);
-        if (source != this) {
-            b.append(source.getName()).append('.');
-        }
-        throw new IllegalArgumentException(Errors.format(key,
-                b.append("properties[").append(index).append("].name").toString()));
+    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
{
+        in.defaultReadObject();
+        computeTransientFields();
     }
 
     /**
@@ -277,7 +265,9 @@ public class DefaultFeatureType extends 
                     done = new IdentityHashMap<>(4); // Guard against infinite recursivity.
                 }
                 if (!isAssignableIgnoreName(previous, property, done)) {
-                    throw new IllegalArgumentException(Errors.format(Errors.Keys.PropertyAlreadyExists_2,
name));
+                    final GenericName owner = ownerOf(previous);
+                    throw new IllegalArgumentException(Errors.format(Errors.Keys.PropertyAlreadyExists_2,
+                            (owner != null) ? owner : "?", name));
                 }
                 done.clear();
             }
@@ -305,17 +295,52 @@ public class DefaultFeatureType extends 
     }
 
     /**
-     * Invoked on deserialization for restoring the {@link #byName} map.
+     * Returns the name of the feature which defines the given property, or {@code null}
if not found.
+     * This method is for information purpose when producing an error message - its implementation
does
+     * not need to be efficient.
+     */
+    private GenericName ownerOf(final PropertyType property) {
+        if (properties.contains(property)) {
+            return getName();
+        }
+        for (final DefaultFeatureType type : superTypes) {
+            final GenericName owner = type.ownerOf(property);
+            if (owner != null) {
+                return owner;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the string representation of the given name, making sure that the name is
non-null
+     * and the string non-empty. This method is used for checking argument validity.
      *
-     * @param  in The input stream from which to deserialize a feature type.
-     * @throws IOException If an I/O error occurred while reading or if the stream contains
invalid data.
-     * @throws ClassNotFoundException If the class serialized on the stream is not on the
classpath.
+     * @param name   The name for which to get the string representation.
+     * @param source The feature which contains the property (typically {@code this}).
+     * @param index  Index of the property having the given name.
      */
-    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
{
-        in.defaultReadObject();
-        computeTransientFields();
+    private String toString(final GenericName name, final DefaultFeatureType source, final
int index) {
+        short key = Errors.Keys.MissingValueForProperty_1;
+        if (name != null) {
+            final String s = name.toString();
+            if (!s.isEmpty()) {
+                return s;
+            }
+            key = Errors.Keys.EmptyProperty_1;
+        }
+        final StringBuilder b = new StringBuilder(30);
+        if (source != this) {
+            b.append(source.getName()).append('.');
+        }
+        throw new IllegalArgumentException(Errors.format(key,
+                b.append("properties[").append(index).append("].name").toString()));
     }
 
+
+    // -------- END OF CONSTRUCTORS ------------------------------------------------------------------------------
+
+
     /**
      * Returns {@code true} if the feature type acts as an abstract super-type.
      *
@@ -444,18 +469,22 @@ public class DefaultFeatureType extends 
 
     /**
      * Returns any feature operation, any feature attribute type and any feature association
role that
-     * carries characteristics of a feature type. The returned list does not include the
characteristics
-     * inherited from the {@linkplain #superTypes() super types}.
+     * carries characteristics of a feature type. The returned collection will include the
properties
+     * inherited from the {@linkplain #superTypes() super-types} only if {@code includeSuperTypes}
is
+     * {@code true}.
      *
      * <div class="warning"><b>Warning:</b>
      * The type of list elements will be changed to {@code PropertyType} if and when such
interface
      * will be defined in GeoAPI.</div>
      *
+     * @param  includeSuperTypes {@code true} for including the properties inherited from
the super-types,
+     *         or {@code false} for returning only the properties defined explicitely in
this type.
      * @return Feature operation, attribute type and association role that carries characteristics
of this
      *         feature type (not including parent types).
      */
-    public List<AbstractIdentifiedType> properties() {
-        return (List) properties; // Cast is safe because the list is read-only.
+    public Collection<AbstractIdentifiedType> properties(final boolean includeSuperTypes)
{
+        // TODO: temporary cast to be removed after we upgraded GeoAPI.
+        return (Collection) (includeSuperTypes ? byName.values() : properties);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java?rev=1594624&r1=1594623&r2=1594624&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java
[UTF-8] Wed May 14 15:54:33 2014
@@ -26,7 +26,7 @@
  *       {@linkplain org.apache.sis.feature.DefaultAttributeType attributes},
  *       {@linkplain org.apache.sis.feature.DefaultOperation operations} or
  *       {@linkplain org.apache.sis.feature.DefaultAssociationRole associations to other
features}
- *       (collectively called “{@linkplain org.apache.sis.feature.DefaultFeatureType#properties()
properties}”
+ *       (collectively called “{@linkplain org.apache.sis.feature.DefaultFeatureType#properties(boolean)
properties}”
  *       or “characteristics”) that a feature can have.</p>
  *
  *       <div class="note"><b>Analogy:</b> a {@code FeatureType} in a Spatial
Information System is equivalent to a

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java?rev=1594624&r1=1594623&r2=1594624&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationRoleTest.java
[UTF-8] Wed May 14 15:54:33 2014
@@ -38,8 +38,8 @@ public final strictfp class DefaultAssoc
      * Creates an association.
      */
     static DefaultAssociationRole twinTown() {
-        return new DefaultAssociationRole(singletonMap(DefaultAssociationRole.NAME_KEY, "Twin
town"),
-                DefaultFeatureTypeTest.cityPopulation(), 0, Integer.MAX_VALUE);
+        return new DefaultAssociationRole(singletonMap(DefaultAssociationRole.NAME_KEY, "twin
town"),
+                DefaultFeatureTypeTest.city(), 0, Integer.MAX_VALUE);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java?rev=1594624&r1=1594623&r2=1594624&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultAssociationTest.java
[UTF-8] Wed May 14 15:54:33 2014
@@ -44,7 +44,7 @@ public final strictfp class DefaultAssoc
      * and Le Mans, France in 836.” — source: Wikipedia</blockquote>
      */
     static DefaultAssociation twinTown() {
-        final DefaultFeature twinTown = new DefaultFeature(DefaultFeatureTypeTest.cityPopulation());
+        final DefaultFeature twinTown = new DefaultFeature(DefaultFeatureTypeTest.city());
         twinTown.setPropertyValue("city", "Le Mans");
         twinTown.setPropertyValue("population", 148169);
         final DefaultAssociation association = new DefaultAssociation(DefaultAssociationRoleTest.twinTown());
@@ -65,9 +65,9 @@ public final strictfp class DefaultAssoc
             association.setValue(otherFeature);
         } catch (IllegalArgumentException e) {
             final String message = e.getMessage();
-            assertTrue(message, message.contains("Twin town"));
+            assertTrue(message, message.contains("twin town"));
             assertTrue(message, message.contains("Population"));
-            assertTrue(message, message.contains("City population"));
+            assertTrue(message, message.contains("City"));
         }
     }
 

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java?rev=1594624&r1=1594623&r2=1594624&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/DefaultFeatureTest.java
[UTF-8] Wed May 14 15:54:33 2014
@@ -42,7 +42,7 @@ public final strictfp class DefaultFeatu
      */
     @Test
     public void testSimple() {
-        final DefaultFeature cityPopulation = new DefaultFeature(DefaultFeatureTypeTest.cityPopulation());
+        final DefaultFeature cityPopulation = new DefaultFeature(DefaultFeatureTypeTest.city());
 
         assertEquals("Utopia", cityPopulation.getPropertyValue("city"));
         cityPopulation.setPropertyValue("city", "Atlantide");

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=1594624&r1=1594623&r2=1594624&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] Wed May 14 15:54:33 2014
@@ -18,13 +18,14 @@ package org.apache.sis.feature;
 
 import java.util.Map;
 import java.util.HashMap;
-import java.util.List;
+import java.util.Iterator;
+import java.util.Collection;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.apache.sis.test.Assert.*;
 import static java.util.Collections.singletonMap;
 
 
@@ -40,54 +41,98 @@ import static java.util.Collections.sing
 public final strictfp class DefaultFeatureTypeTest extends TestCase {
     /**
      * Creates a simple feature type without super-types.
+     * The feature contains the following attribute:
+     *
+     * <ul>
+     *   <li>{@code city}       as a  {@link String}  (mandatory)</li>
+     *   <li>{@code population} as an {@link Integer} (mandatory)</li>
+     * </ul>
      */
-    static DefaultFeatureType cityPopulation() {
+    static DefaultFeatureType city() {
         final Map<String,Object> identification = new HashMap<>();
         final DefaultAttributeType<String>  city       = DefaultAttributeTypeTest.city(identification);
         final DefaultAttributeType<Integer> population = DefaultAttributeTypeTest.population(identification);
 
         identification.clear();
-        assertNull(identification.put(DefaultFeatureType.NAME_KEY, "City population"));
+        assertNull(identification.put(DefaultFeatureType.NAME_KEY, "City"));
         return new DefaultFeatureType(identification, false, null, city, population);
     }
 
     /**
      * Creates a sub-type of the "city" type with only one additional property,
-     * a string giving the date since the city is a capital.
+     * a string giving the parliament name.
      *
      * <p>We do not specify the country, since this will be the purpose of an other
test class.</p>
      */
     static DefaultFeatureType capital() {
-        return new DefaultFeatureType(singletonMap(DefaultFeatureType.NAME_KEY, "capital"),
false,
-                new DefaultFeatureType[] {cityPopulation()},
-                new DefaultAttributeType<>(singletonMap(DefaultAttributeType.NAME_KEY,
"since"),
+        return new DefaultFeatureType(singletonMap(DefaultFeatureType.NAME_KEY, "Capital"),
false,
+                new DefaultFeatureType[] {city()},
+                new DefaultAttributeType<>(singletonMap(DefaultAttributeType.NAME_KEY,
"parliament"),
                         String.class, 1, 1, null));
     }
 
     /**
+     * Returns the string representation of the names of all properties in the given collection.
+     */
+    private static String[] getNames(final Collection<? extends AbstractIdentifiedType>
properties) {
+        final String[] names = new String[properties.size()];
+        int index = 0;
+        for (final AbstractIdentifiedType property : properties) {
+            assertNotNull(properties);
+            names[index++] = property.getName().toString();
+        }
+        assertEquals(names.length, index);
+        return names;
+    }
+
+    /**
+     * Performs some basic validations on the given feature.
+     */
+    private static void validate(final DefaultFeatureType feature) {
+        final Collection<?> explicitProperties = feature.properties(false);
+        final Collection<?> allProperties = feature.properties(true);
+        assertTrue("'properties(true)' shall contain all 'properties(false)' elements.",
+                allProperties.containsAll(explicitProperties));
+        try {
+            explicitProperties.clear();
+            fail("Properties collection shall not be modifiable.");
+        } catch (UnsupportedOperationException e) {
+            assertFalse(explicitProperties.isEmpty());
+        }
+        try {
+            allProperties.clear();
+            fail("Properties collection shall not be modifiable.");
+        } catch (UnsupportedOperationException e) {
+            assertFalse(allProperties.isEmpty());
+        }
+    }
+
+    /**
      * Tests the construction of a simple feature without super-types.
      * A feature is said "simple" if the cardinality of all attributes is [1 … 1].
      */
     @Test
     public void testSimple() {
-        final DefaultFeatureType simple = cityPopulation();
-        assertEquals("name", "City population", simple.getName().toString());
+        final DefaultFeatureType simple = city();
+        assertEquals("name", "City",    simple.getName().toString());
         assertEquals("instanceSize", 2, simple.getInstanceSize());
         assertFalse ("isAbstract",      simple.isAbstract());
         assertTrue  ("isSimple",        simple.isSimple());
+        validate(simple);
         /*
          * Verify content.
          */
-        final List<AbstractIdentifiedType> properties = simple.properties();
-        assertEquals("properties.size", 2,            properties.size());
-        assertEquals("properties[0]",   "city",       properties.get(0).getName().toString());
-        assertEquals("properties[1]",   "population", properties.get(1).getName().toString());
+        assertArrayEquals("properties",
+                new String[] {"city", "population"},
+                getNames(simple.properties(false)));
         /*
          * Verify search by name.
          */
-        assertSame(properties.get(0), simple.getProperty("city"));
-        assertSame(properties.get(1), simple.getProperty("population"));
-        assertNull(                        simple.getProperty("apple"));
+        final Iterator<AbstractIdentifiedType> it = simple.properties(false).iterator();
+        assertSame(it.next(), simple.getProperty("city"));
+        assertSame(it.next(), simple.getProperty("population"));
+        assertNull(           simple.getProperty("apple"));
+        assertFalse(it.hasNext());
     }
 
     /**
@@ -101,40 +146,44 @@ public final strictfp class DefaultFeatu
         final Map<String,Object> identification = new HashMap<>();
         final DefaultAttributeType<String>  city       = DefaultAttributeTypeTest.city(identification);
         final DefaultAttributeType<Integer> population = DefaultAttributeTypeTest.population(identification);
-        identification.clear();
-        for (int i=0; i<=4; i++) {
-            final int minimumOccurs, maximumOccurs;
-            switch (i) {
-                case 0: minimumOccurs = 0; maximumOccurs = 0; break; // Simple
-                case 1: minimumOccurs = 0; maximumOccurs = 1; break;
-                case 2: minimumOccurs = 0; maximumOccurs = 2; break;
-                case 3: minimumOccurs = 1; maximumOccurs = 2; break;
-                case 4: minimumOccurs = 1; maximumOccurs = 1; break; // Simple
-                default: throw new AssertionError(i);
-            }
-            identification.put(DefaultAttributeType.NAME_KEY, "festival");
-            final DefaultAttributeType<String> festival = new DefaultAttributeType<>(
-                    identification, String.class, minimumOccurs, maximumOccurs, null);
-            /*
-             * Build the feature.
-             */
-            identification.put(DefaultAttributeType.NAME_KEY, "City festival");
-            final DefaultFeatureType complex = new DefaultFeatureType(identification, false,
null, city, population, festival);
-            final List<AbstractIdentifiedType> properties = complex.properties();
-            /*
-             * Verify content.
-             */
-            assertEquals("name",            "City festival",                complex.getName().toString());
-            assertFalse ("isAbstract",                                      complex.isAbstract());
-            assertEquals("isSimple",        maximumOccurs == minimumOccurs, complex.isSimple());
-            assertEquals("instanceSize",    maximumOccurs == 0 ? 2 : 3,     complex.getInstanceSize());
-            assertEquals("properties.size", 3,                              properties.size());
-            assertSame  ("properties[0]",   city,                           properties.get(0));
-            assertSame  ("properties[1]",   population,                     properties.get(1));
-            assertSame  ("properties[3]",   festival,                       properties.get(2));
-            assertEquals("minimumOccurs",   minimumOccurs,                  festival.getMinimumOccurs());
-            assertEquals("maximumOccurs",   maximumOccurs,                  festival.getMaximumOccurs());
-        }
+        testComplex(city, population, 0, 0); // Simple
+        testComplex(city, population, 0, 1);
+        testComplex(city, population, 0, 2);
+        testComplex(city, population, 1, 2);
+        testComplex(city, population, 1, 1); // Simple
+    }
+
+    /**
+     * Implementation of {@link #testComplex()} for the given minimum and maximum occurrences.
+     */
+    private static void testComplex(
+            final DefaultAttributeType<String>  city,
+            final DefaultAttributeType<Integer> population,
+            final int minimumOccurs, final int maximumOccurs)
+    {
+        final DefaultAttributeType<String> festival = new DefaultAttributeType<>(
+                singletonMap(DefaultAttributeType.NAME_KEY, "festival"),
+                String.class, minimumOccurs, maximumOccurs, null);
+
+        final DefaultFeatureType complex = new DefaultFeatureType(
+                singletonMap(DefaultAttributeType.NAME_KEY, "Festival"),
+                false, null, city, population, festival);
+
+        validate(complex);
+        final Collection<AbstractIdentifiedType> properties = complex.properties(false);
+        final Iterator<AbstractIdentifiedType> it = properties.iterator();
+
+        assertEquals("name",            "Festival",                     complex.getName().toString());
+        assertFalse ("isAbstract",                                      complex.isAbstract());
+        assertEquals("isSimple",        maximumOccurs == minimumOccurs, complex.isSimple());
+        assertEquals("instanceSize",    maximumOccurs == 0 ? 2 : 3,     complex.getInstanceSize());
+        assertEquals("minimumOccurs",   minimumOccurs,                  festival.getMinimumOccurs());
+        assertEquals("maximumOccurs",   maximumOccurs,                  festival.getMaximumOccurs());
+        assertEquals("properties.size", 3,                              properties.size());
+        assertSame  ("properties[0]",   city,                           it.next());
+        assertSame  ("properties[1]",   population,                     it.next());
+        assertSame  ("properties[3]",   festival,                       it.next());
+        assertFalse (it.hasNext());
     }
 
     /**
@@ -144,19 +193,20 @@ public final strictfp class DefaultFeatu
     @DependsOnMethod("testSimple")
     public void testNameCollision() {
         final DefaultAttributeType<String> city = new DefaultAttributeType<>(
-                singletonMap(DefaultAttributeType.NAME_KEY, "city"), String.class, 1, 1,
null);
+                singletonMap(DefaultAttributeType.NAME_KEY, "name"), String.class, 1, 1,
null);
         final DefaultAttributeType<Integer> cityId = new DefaultAttributeType<>(
-                singletonMap(DefaultAttributeType.NAME_KEY, "city"), Integer.class, 1, 1,
null);
+                singletonMap(DefaultAttributeType.NAME_KEY, "name"), Integer.class, 1, 1,
null);
         final DefaultAttributeType<Integer> population = new DefaultAttributeType<>(
                 singletonMap(DefaultAttributeType.NAME_KEY, "population"), Integer.class,
1, 1, null);
 
-        final Map<String,String> identification = singletonMap(DefaultAttributeType.NAME_KEY,
"City population");
+        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.");
         } catch (IllegalArgumentException e) {
             final String message = e.getMessage();
-            assertTrue(message, message.contains("city"));
+            assertTrue(message, message.contains("name")); // Property name.
+            assertTrue(message, message.contains("City")); // Feature name.
         }
     }
 
@@ -164,10 +214,10 @@ public final strictfp class DefaultFeatu
      * Tests a feature type which inherit from an other feature type.
      */
     @Test
-    @DependsOnMethod("testSimple")
+    @DependsOnMethod("testComplex")
     public void testInheritance() {
         final DefaultFeatureType capital = capital();
-        final DefaultFeatureType city = cityPopulation();
+        final DefaultFeatureType city = city();
 
         // Check based only on name.
         assertTrue ("maybeAssignableFrom", city.maybeAssignableFrom(capital));
@@ -176,23 +226,39 @@ public final strictfp class DefaultFeatu
         // Public API.
         assertTrue ("isAssignableFrom", city.isAssignableFrom(capital));
         assertFalse("isAssignableFrom", capital.isAssignableFrom(city));
-        /*
-         * Verify content.
-         */
-        List<AbstractIdentifiedType> properties = city.properties();
-        assertEquals("properties.size", 2,            properties.size());
-        assertEquals("properties[0]",   "city",       properties.get(0).getName().toString());
-        assertEquals("properties[1]",   "population", properties.get(1).getName().toString());
-
-        properties = capital.properties();
-        assertEquals("properties.size", 1,            properties.size());
-        assertEquals("properties[0]",   "since",      properties.get(0).getName().toString());
-        /*
-         * Verify search by name.
-         */
+
+        assertArrayEquals("properties",
+                new String[] {"city", "population"},
+                getNames(city.properties(false)));
+
+        verifyCapital(capital);
+    }
+
+    /**
+     * Verifies the content of a feature created by {@link #capital()}.
+     */
+    private static void verifyCapital(final DefaultFeatureType capital) {
+        assertArrayEquals("properties",
+                new String[] {"parliament"},
+                getNames(capital.properties(false)));
+
+        assertArrayEquals("properties",
+                new String[] {"city", "population", "parliament"},
+                getNames(capital.properties(true)));
+
         assertEquals("city",       capital.getProperty("city")      .getName().toString());
         assertEquals("population", capital.getProperty("population").getName().toString());
-        assertEquals("since",      capital.getProperty("since")     .getName().toString());
+        assertEquals("parliament", capital.getProperty("parliament").getName().toString());
         assertNull  (              capital.getProperty("apple"));
     }
+
+    /**
+     * Tests serialization.
+     */
+    @Test
+    @DependsOnMethod("testInheritance")
+    public void testSerialization() {
+        final DefaultFeatureType capital = capital();
+        verifyCapital(assertSerializedEquals(capital));
+    }
 }



Mime
View raw message