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 2020/12/05 15:28:36 UTC

[commons-collections] 01/03: Break up test getFromMap() by map type.

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-collections.git

commit 69f06d60f69ada39ed211f590fa6a963d20fe3f5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 5 10:23:45 2020 -0500

    Break up test getFromMap() by map type.
---
 .../commons/collections4/CollectionUtilsTest.java  | 48 +++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
index 1afdb78..489f1b5 100644
--- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
@@ -34,6 +34,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -982,7 +983,7 @@ public class CollectionUtilsTest extends MockTestCase {
     }
 
     @Test
-    public void getFromMap() {
+    public void getFromHashMap() {
         // Unordered map, entries exist
         final Map<String, String> expected = new HashMap<>();
         expected.put("zeroKey", "zero");
@@ -1006,6 +1007,51 @@ public class CollectionUtilsTest extends MockTestCase {
         } catch (final IndexOutOfBoundsException e) {
             // expected
         }
+    }
+
+    @Test
+    public void getFromLinkedHashMap() {
+        // Ordered map, entries exist
+        final Map<String, String> expected = new LinkedHashMap<>();
+        expected.put("zeroKey", "zero");
+        expected.put("oneKey", "one");
+
+        final Map<String, String> found = new LinkedHashMap<>();
+        Map.Entry<String, String> entry = CollectionUtils.get(expected, 0);
+        found.put(entry.getKey(), entry.getValue());
+        entry = CollectionUtils.get(expected, 1);
+        found.put(entry.getKey(), entry.getValue());
+        assertEquals(expected, found);
+    }
+
+    @Test
+    public void getFromMapIndexOutOfRange() {
+        // Ordered map, entries exist
+        final Map<String, String> expected = new LinkedHashMap<>();
+        expected.put("zeroKey", "zero");
+        expected.put("oneKey", "one");
+
+        // Map index out of range
+        try {
+            CollectionUtils.get(expected, 2);
+            fail("Expecting IndexOutOfBoundsException.");
+        } catch (final IndexOutOfBoundsException e) {
+            // expected
+        }
+        try {
+            CollectionUtils.get(expected, -2);
+            fail("Expecting IndexOutOfBoundsException.");
+        } catch (final IndexOutOfBoundsException e) {
+            // expected
+        }
+     }
+
+    @Test
+    public void getFromTreeMap() {
+        // Ordered map, entries exist
+        final Map<String, String> expected = new LinkedHashMap<>();
+        expected.put("zeroKey", "zero");
+        expected.put("oneKey", "one");
 
         // Sorted map, entries exist, should respect order
         final SortedMap<String, String> map = new TreeMap<>();