sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1533395 - in /sis/branches/JDK7/core/sis-utility/src: main/java/org/apache/sis/internal/util/CollectionsExt.java test/java/org/apache/sis/internal/util/CollectionsExtTest.java
Date Fri, 18 Oct 2013 11:28:25 GMT
Author: desruisseaux
Date: Fri Oct 18 11:28:24 2013
New Revision: 1533395

URL: http://svn.apache.org/r1533395
Log:
Added a test case.

Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1533395&r1=1533394&r2=1533395&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] Fri Oct 18 11:28:24 2013
@@ -175,6 +175,7 @@ public final class CollectionsExt extend
     public static <E> E[] nonNullArraySet(final String name, final Object value, final
E[] emptyArray)
             throws IllegalArgumentException
     {
+        assert emptyArray.length == 0;
         if (value == null) {
             return emptyArray;
         }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java?rev=1533395&r1=1533394&r2=1533395&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/util/CollectionsExtTest.java
[UTF-8] Fri Oct 18 11:28:24 2013
@@ -39,11 +39,42 @@ import org.apache.sis.internal.jdk8.Func
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final strictfp class CollectionsExtTest extends TestCase {
     /**
+     * Tests {@link CollectionsExt#nonNullArraySet(String, Object, Object[])}.
+     */
+    @Test
+    public void testNonNullArraySet() {
+        final String name = "test";
+        final String[] emptyArray = new String[0];
+        assertSame(emptyArray,
+                CollectionsExt.nonNullArraySet(name, null, emptyArray));
+        assertSame(emptyArray,
+                CollectionsExt.nonNullArraySet(name, emptyArray, emptyArray));
+        assertArrayEquals(new String[] {"A"},
+                CollectionsExt.nonNullArraySet(name, "A", emptyArray));
+        assertArrayEquals(new String[] {"A"},
+                CollectionsExt.nonNullArraySet(name, new String[] {"A", null, "A"}, emptyArray));
+        assertArrayEquals(new String[] {"B", "A", "C"},
+                CollectionsExt.nonNullArraySet(name, new String[] {"B", "A", "B", "C", null,
"A"}, emptyArray));
+        /*
+         * Verify that an exception is thrown in case of illegal value type.  Note that the
Object[] type
+         * could be accepted if all elements are String instances, however the current method
contract is
+         * to not accept them, so we will ensure that.
+         */
+        try {
+            CollectionsExt.nonNullArraySet(name, new Object[] {"A"}, emptyArray);
+        } catch (IllegalArgumentException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains(name));
+            assertTrue(message, message.contains("Object[]"));
+        }
+    }
+
+    /**
      * Tests {@link CollectionsExt#addToMultiValuesMap(Map, Object, Object)}.
      */
     @Test



Mime
View raw message