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/11/04 00:02:09 UTC

[commons-collections] branch master updated: Add test cases in UnmodifiableMultiValuedMapTest (#102)

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


The following commit(s) were added to refs/heads/master by this push:
     new fbe9566  Add test cases in UnmodifiableMultiValuedMapTest (#102)
fbe9566 is described below

commit fbe9566e128a039c7d857576127a6b4702f37c77
Author: dota17 <50...@users.noreply.github.com>
AuthorDate: Mon Nov 4 08:02:04 2019 +0800

    Add test cases in UnmodifiableMultiValuedMapTest (#102)
    
    * Add test cases in UnmodifiableMultiValuedMapTest
    
    * remove import * and comment empty code blocks
---
 .../multimap/UnmodifiableMultiValuedMapTest.java   | 79 +++++++++++++++++++++-
 1 file changed, 76 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java
index 260d9ae..ca4527e 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/UnmodifiableMultiValuedMapTest.java
@@ -16,12 +16,13 @@
  */
 package org.apache.commons.collections4.multimap;
 
+import java.util.Set;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.HashMap;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
 
 import junit.framework.Test;
 
@@ -100,6 +101,78 @@ public class UnmodifiableMultiValuedMapTest<K, V> extends AbstractMultiValuedMap
         }
     }
 
+    public void testRemoveException() {
+        final MultiValuedMap<K, V> map = makeFullMap();
+        try {
+            map.remove((K) "one");
+            fail();
+        } catch (final UnsupportedOperationException e) {
+            // expected, not support remove() method
+            // UnmodifiableMultiValuedMap does not support change
+        }
+        assertEquals("{one=[uno, un], two=[dos, deux], three=[tres, trois]}", map.toString());
+    }
+
+    public void testRemoveMappingException() {
+        final MultiValuedMap<K, V> map = makeFullMap();
+        try {
+            map.removeMapping((K) "one", (V) "uno");
+            fail();
+        } catch (final UnsupportedOperationException e) {
+            // expected, not support removeMapping() method
+            // UnmodifiableMultiValuedMap does not support change
+        }
+        assertEquals("{one=[uno, un], two=[dos, deux], three=[tres, trois]}", map.toString());
+    }
+
+    public void testClearException() {
+        final MultiValuedMap<K, V> map = makeFullMap();
+        try {
+            map.clear();
+            fail();
+        } catch (final UnsupportedOperationException e) {
+            // expected, not support clear() method
+            // UnmodifiableMultiValuedMap does not support change
+        }
+        assertEquals("{one=[uno, un], two=[dos, deux], three=[tres, trois]}", map.toString());
+    }
+
+    public void testPutAllException() {
+        final MultiValuedMap<K, V> map = makeObject();
+        final MultiValuedMap<K, V> original = new ArrayListValuedHashMap<>();
+        final Map<K, V> originalMap = new HashMap<>();
+        final Collection<V> coll = (Collection<V>) Arrays.asList("X", "Y", "Z");
+        original.put((K) "key", (V) "object1");
+        original.put((K) "key", (V) "object2");
+        originalMap.put((K) "keyX", (V) "object1");
+        originalMap.put((K) "keyY", (V) "object2");
+
+        try {
+            map.putAll(original);
+            fail();
+        } catch (final UnsupportedOperationException e) {
+            // expected, not support putAll() method
+            // UnmodifiableMultiValuedMap does not support change
+        }
+        assertEquals("{}", map.toString());
+
+        try {
+            map.putAll(originalMap);
+            fail();
+        } catch (final UnsupportedOperationException e) {
+            // expected
+        }
+        assertEquals("{}", map.toString());
+
+        try {
+            map.putAll((K) "A", coll);
+            fail();
+        } catch (final UnsupportedOperationException e) {
+            // expected
+        }
+        assertEquals("{}", map.toString());
+    }
+
     @SuppressWarnings("unchecked")
     public void testUnmodifiableEntries() {
         resetFull();