You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/25 13:15:18 UTC

[commons-lang] branch master updated: Add more test inputs for ArrayUtils.toMap() method (#472)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 54afdb3  Add more test inputs for ArrayUtils.toMap() method (#472)
54afdb3 is described below

commit 54afdb303535a62fe00e49e3ad5100ca9fc55d1e
Author: apirom9 <ap...@gmail.com>
AuthorDate: Fri Oct 25 20:15:08 2019 +0700

    Add more test inputs for ArrayUtils.toMap() method (#472)
    
    * Add more test inputs for ArrayUtils.toMap() method in case zero-length array, all null values array, and duplicate keys in array
    
    * Fixed style
    
    * Fixed style
    
    * Fixed as changed request
    
    * Remove unused import statement
---
 src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index 4b7c31d..069466e 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
@@ -30,6 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.Map;
@@ -264,6 +265,17 @@ public class ArrayUtilsTest {
             }
         }});
         assertEquals("bar", map.get("foo"));
+
+        // Return empty map when got input array with length = 0
+        assertEquals(Collections.emptyMap(), ArrayUtils.toMap(new Object[0]));
+
+        // Test all null values
+        map = ArrayUtils.toMap(new Object[][] { {null, null}, {null, null} });
+        assertEquals(Collections.singletonMap(null, null), map);
+
+        // Test duplicate keys
+        map = ArrayUtils.toMap(new Object[][] { {"key", "value2"}, {"key", "value1"} });
+        assertEquals(Collections.singletonMap("key", "value1"), map);
     }
 
     //-----------------------------------------------------------------------