commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [commons-collections] branch master updated: Update test cases (#104)
Date Fri, 01 Nov 2019 15:31:03 GMT
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 869993d  Update test cases (#104)
869993d is described below

commit 869993da9790cc56c0597fd18012498f07ad292a
Author: dota17 <50514813+dota17@users.noreply.github.com>
AuthorDate: Fri Nov 1 23:30:54 2019 +0800

    Update test cases (#104)
    
    * Add three test cases in HashSetValuedHashMapTest
    
    * Update test cases
---
 .../multimap/AbstractMultiValuedMapTest.java       |  1 +
 .../multimap/HashSetValuedHashMapTest.java         | 53 ++++++++++++++++++++++
 .../multimap/TransformedMultiValuedMapTest.java    | 11 +++++
 3 files changed, 65 insertions(+)

diff --git a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java
b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java
index 444546f..b821e79 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java
@@ -688,6 +688,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
         assertEquals(2, keyMultiSet.getCount("one"));
         assertEquals(2, keyMultiSet.getCount("two"));
         assertEquals(2, keyMultiSet.getCount("three"));
+        assertEquals(0, keyMultiSet.getCount("conut"));
         assertEquals(6, keyMultiSet.size());
     }
 
diff --git a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java
b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java
index 2a46641..8a33998 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java
@@ -16,7 +16,9 @@
  */
 package org.apache.commons.collections4.multimap;
 
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 
 import junit.framework.Test;
@@ -125,6 +127,57 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
         assertNotSame(map1.hashCode(), map2.hashCode());
     }
 
+    public void testHashSetValueHashMap() {
+        final SetValuedMap<K, V> setMap = new HashSetValuedHashMap<>(4);
+        assertEquals(0, setMap.get((K) "whatever").size());
+
+        final Set<V> set = setMap.get((K) "A");
+        set.add((V) "W");
+        set.add((V) "X");
+        set.add((V) "F");
+        assertEquals(3, setMap.get((K) "A").size());
+    }
+
+    public void testHashSetValueHashMap_1() {
+        final MultiValuedMap<K, V> map = new ArrayListValuedHashMap<>();
+        SetValuedMap<K, V> map1 = null;
+        SetValuedMap<K, V> map2 = makeObject();
+        SetValuedMap<K, V> map3 = null;
+
+        map.put((K) "A", (V) "W");
+        map.put((K) "A", (V) "X");
+        map.put((K) "A", (V) "F");
+        map1 = new HashSetValuedHashMap<>(map);
+        assertEquals(3, map1.get((K) "A").size());
+        map2.put((K) "A", (V) "X");
+        map2.put((K) "A", (V) "F");
+        map2.put((K) "A", (V) "W");
+        assertEquals(map1, map2);
+        assertEquals(map1.hashCode(), map2.hashCode());
+
+        map.remove("A");
+        map3 = new HashSetValuedHashMap<>(map);
+        assertEquals("{}", map3.toString());
+    }
+
+    public void testHashSetValuedHashMap_2(){
+        final Map<K, V> map = new HashMap<>();
+        SetValuedMap<K, V> map1 = null;
+        SetValuedMap<K, V> map2 = null;
+
+        map.put((K) "A", (V) "W");
+        map.put((K) "B", (V) "X");
+        map.put((K) "C", (V) "F");
+        map1 = new HashSetValuedHashMap<>(map);
+        assertEquals(1, map1.get((K) "A").size());
+
+        map.remove("A");
+        map.remove("B");
+        map.remove("C");
+        map2 = new HashSetValuedHashMap<>(map);
+        assertEquals("{}", map2.toString());
+    }
+
 //    public void testCreate() throws Exception {
 //        writeExternalFormToDisk((java.io.Serializable) makeObject(),
 //                "src/test/resources/data/test/HashSetValuedHashMap.emptyCollection.version4.1.obj");
diff --git a/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java
b/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java
index ed0723e..0f9c12e 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java
@@ -131,6 +131,17 @@ public class TransformedMultiValuedMapTest<K, V> extends AbstractMultiValuedMapT
         assertEquals(true, trans.get((K) "C").contains(Integer.valueOf(3)));
         trans.put((K) "D", (V) "4");
         assertEquals(true, trans.get((K) "D").contains(Integer.valueOf(4)));
+
+        final MultiValuedMap<K, V> baseMap = new ArrayListValuedHashMap<>();
+        final MultiValuedMap<K, V> transMap = TransformedMultiValuedMap
+                .transformedMap(
+                        baseMap,
+                        null,
+                        (Transformer<? super V, ? extends V>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
+        assertEquals(0, transMap.size());
+        transMap.put((K) "D", (V) "4");
+        assertEquals(1, transMap.size());
+        assertEquals(true, transMap.get((K) "D").contains(Integer.valueOf(4)));
     }
 
 //    public void testCreate() throws Exception {


Mime
View raw message