Author: desruisseaux
Date: Tue Mar 17 11:45:09 2015
New Revision: 1667277

URL: http://svn.apache.org/r1667277
Log:
Referencing: added a test for the case where a parameter group contains 
sub-groups.

Modified:
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
    
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorGroupTest.java
    
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java
    
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java?rev=1667277&r1=1667276&r2=1667277&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterValueList.java
 [UTF-8] Tue Mar 17 11:45:09 2015
@@ -67,6 +67,7 @@ final class ParameterValueList extends A
 
     /**
      * The parameter values in the group. The length of this array is the list 
capacity.
+     * This array will growth as needed.
      */
     private GeneralParameterValue[] values;
 

Modified: 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorGroupTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorGroupTest.java?rev=1667277&r1=1667276&r2=1667277&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorGroupTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorGroupTest.java
 [UTF-8] Tue Mar 17 11:45:09 2015
@@ -47,6 +47,11 @@ import static org.opengis.referencing.Id
 @DependsOn(DefaultParameterDescriptorTest.class)
 public final strictfp class DefaultParameterDescriptorGroupTest extends 
TestCase {
     /**
+     * The default value used by the parameters in the {@link #M1_M1_O1_O2} 
descriptor.
+     */
+    static final Integer DEFAULT_VALUE = 10;
+
+    /**
      * A group of 4 parameters of type {@link Integer} with default value 10.
      * The two first parameters are mandatory, while the two last parameters 
are optional.
      * The very last parameter has a maximum number of occurrence of 2, which 
is illegal
@@ -54,7 +59,6 @@ public final strictfp class DefaultParam
      */
     static final DefaultParameterDescriptorGroup M1_M1_O1_O2;
     static {
-        final Integer DEFAULT_VALUE = 10;
         final Class<Integer> type = Integer.class;
         final Map<String,Object> properties = new HashMap<>(4);
         M1_M1_O1_O2 = new 
DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, "Test group"), 0, 1,

Modified: 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java?rev=1667277&r1=1667276&r2=1667277&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterValueGroupTest.java
 [UTF-8] Tue Mar 17 11:45:09 2015
@@ -18,6 +18,7 @@ package org.apache.sis.parameter;
 
 import java.util.List;
 import java.util.Arrays;
+import java.util.ArrayList;
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.parameter.ParameterDescriptor;
@@ -42,7 +43,7 @@ import static org.opengis.referencing.Id
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.6
  * @module
  */
 @DependsOn({
@@ -143,8 +144,8 @@ public final strictfp class DefaultParam
         assertEquals("parameter(“Mandatory 2”)", 20, 
group.parameter("Mandatory 2").intValue());
         values.clear();
         assertEquals("size", 2, values.size());
-        assertEquals("parameter(“Mandatory 2”)", 10, 
group.parameter("Mandatory 2").intValue());
-        // The above 10 is the default value specified by the descriptor.
+        assertEquals("parameter(“Mandatory 2”)", 
DefaultParameterDescriptorGroupTest.DEFAULT_VALUE,
+                group.parameter("Mandatory 2").getValue());
     }
 
     /**
@@ -164,9 +165,8 @@ public final strictfp class DefaultParam
         } catch (IndexOutOfBoundsException e) {
             assertNotNull(e.getMessage());
         }
-        assertEquals(10, ((ParameterValue<?>) values.get(0)).intValue());
-        assertEquals(10, ((ParameterValue<?>) values.get(1)).intValue());
-        // 10 is the default value specified by the descriptor.
+        assertEquals(DefaultParameterDescriptorGroupTest.DEFAULT_VALUE, 
((ParameterValue<?>) values.get(0)).getValue());
+        assertEquals(DefaultParameterDescriptorGroupTest.DEFAULT_VALUE, 
((ParameterValue<?>) values.get(1)).getValue());
     }
 
     /**
@@ -229,6 +229,63 @@ public final strictfp class DefaultParam
     }
 
     /**
+     * Tests {@code DefaultParameterValueGroup.values().addAll(…)} with 
subgroups.
+     *
+     * @since 0.6
+     */
+    @Test
+    @DependsOnMethod({"testValuesAddAll", "testAddGroup"})
+    public void testValuesAddAllWithSubgroups() {
+        final DefaultParameterDescriptorGroup group, subGroup;
+        final List<GeneralParameterDescriptor> descriptors = new 
ArrayList<>(descriptor.descriptors());
+        subGroup = new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, 
"theSubGroup"),
+                2, 4, descriptors.toArray(new 
GeneralParameterDescriptor[descriptors.size()]));
+        descriptors.add(subGroup);
+        group = new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, 
"theGroup"),
+                descriptors.toArray(new 
GeneralParameterDescriptor[descriptors.size()]));
+        /*
+         * Prepare the GeneralParameterValue instances that we are going to 
add in the above group.
+         * We assign arbitrary integer values to each instance if order to be 
able to differentiate
+         * them, but the purpose of this test is not to verify those integer 
values.
+         *
+         * We intentionally:
+         *   - Omit the creation of a mandatory parameter value
+         *   - Create more sub-groups than the minimum required.
+         */
+        final ParameterValue<?>   v2 = (ParameterValue<?>) 
descriptor.descriptor("Mandatory 2").createValue();
+        final ParameterValue<?>   v3 = (ParameterValue<?>) 
descriptor.descriptor( "Optional 3").createValue();
+        final ParameterValueGroup g1 = subGroup.createValue();
+        final ParameterValueGroup g2 = subGroup.createValue();
+        final ParameterValueGroup g3 = subGroup.createValue();
+        v2.setValue(4);
+        v3.setValue(8);
+        g1.parameter("Mandatory 1").setValue(3);
+        g2.parameter( "Optional 4").setValue(7);
+        g3.parameter("Mandatory 2").setValue(5);
+        final List<GeneralParameterValue> expected = new ArrayList<>(6);
+        assertTrue(expected.add(v2));
+        assertTrue(expected.add(v3));
+        assertTrue(expected.add(g1));
+        assertTrue(expected.add(g2));
+        assertTrue(expected.add(g3));
+        /*
+         * A newly created group should be initialized with 4 
GeneralParameterValue instances because of
+         * the mandatory ones. After we added our own instances created above, 
the group should contains
+         * 6 instances (one more than what we added) because of the "Mandatory 
1" parameter that we did
+         * not provided. Note that the element order in the 'values' 
collection does not need to be the
+         * order in which we provided our GeneralParameterValue instances.
+         */
+        final List<GeneralParameterValue> values = 
group.createValue().values();
+        assertEquals("Initial size", 4,         values.size());
+        assertTrue  ("List shall be modified",  values.addAll(expected));
+        assertEquals("Size after addAll(…)", 6, values.size());
+        final ParameterValue<?> v1 = (ParameterValue<?>) values.get(0);
+        assertEquals("Default value", 
DefaultParameterDescriptorGroupTest.DEFAULT_VALUE, v1.getValue());
+        assertTrue(expected.add(v1));
+        assertSetEquals(expected, values);
+    }
+
+    /**
      * Tests that attempts to add an invalid parameter cause an {@link 
InvalidParameterNameException} to be thrown.
      */
     @Test

Modified: 
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java?rev=1667277&r1=1667276&r2=1667277&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
 [UTF-8] Tue Mar 17 11:45:09 2015
@@ -18,6 +18,7 @@ package org.apache.sis.test;
 
 import java.util.Set;
 import java.util.Map;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.LinkedHashSet;
 import java.util.LinkedHashMap;
@@ -142,13 +143,15 @@ public strictfp class Assert extends org
     }
 
     /**
-     * Asserts that the given set contains the same elements.
+     * Asserts that the given set contains the same elements, ignoring order.
      * In case of failure, this method lists the missing or unexpected 
elements.
      *
+     * <p>The given collections are typically instances of {@link Set}, but 
this is not mandatory.</p>
+     *
      * @param expected The expected set, or {@code null}.
      * @param actual   The actual set, or {@code null}.
      */
-    public static void assertSetEquals(final Set<?> expected, final Set<?> 
actual) {
+    public static void assertSetEquals(final Collection<?> expected, final 
Collection<?> actual) {
         if (expected != null && actual != null && !expected.isEmpty()) {
             final Set<Object> r = new LinkedHashSet<>(expected);
             assertTrue("The two sets are disjoint.",                 
r.removeAll(actual));
@@ -157,7 +160,9 @@ public strictfp class Assert extends org
             assertTrue("The two sets are disjoint.",                 
r.removeAll(expected));
             assertTrue("The set contains unexpected elements: " + r, 
r.isEmpty());
         }
-        assertEquals("Set.equals(Object) failed:", expected, actual);
+        if (expected instanceof Set<?> && actual instanceof Set<?>) {
+            assertEquals("Set.equals(Object) failed:", expected, actual);
+        }
     }
 
     /**


Reply via email to