You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/09/15 07:57:24 UTC

svn commit: r815125 - /commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCompositeMap.java

Author: bayard
Date: Tue Sep 15 05:57:24 2009
New Revision: 815125

URL: http://svn.apache.org/viewvc?rev=815125&view=rev
Log:
Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.

Also see the following revisions:

    ------------------------------------------------------------------------
    r740150 | mbenson | 2009-02-02 15:24:00 -0800 (Mon, 02 Feb 2009) | 1 line
    
    make all [collections] maps implement IterableMap
    ------------------------------------------------------------------------

Modified:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCompositeMap.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCompositeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCompositeMap.java?rev=815125&r1=815124&r2=815125&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCompositeMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestCompositeMap.java Tue Sep 15 05:57:24 2009
@@ -33,7 +33,7 @@
  *
  * @author Brian McCallister
  */
-public class TestCompositeMap extends AbstractTestMap {
+public class TestCompositeMap<K, V> extends AbstractTestIterableMap<K, V> {
     /** used as a flag in MapMutator tests */
     private boolean pass = false;
     
@@ -55,37 +55,40 @@
         junit.textui.TestRunner.main(testCaseName);
     }
     
-    public Map makeEmptyMap() {
-        CompositeMap map = new CompositeMap();
-        map.addComposited(new HashMap());
+    public CompositeMap<K, V> makeObject() {
+        CompositeMap<K, V> map = new CompositeMap<K, V>();
+        map.addComposited(new HashMap<K, V>());
         map.setMutator( new EmptyMapMutator() );
         return map;
     }
     
-    private Map buildOne() {
-        HashMap map = new HashMap();
-        map.put("1", "one");
-        map.put("2", "two");
+    @SuppressWarnings("unchecked")
+    private Map<K, V> buildOne() {
+        HashMap<K, V> map = new HashMap<K, V>();
+        map.put((K) "1", (V) "one");
+        map.put((K) "2", (V) "two");
         return map;
     }
     
-    public Map buildTwo() {
-        HashMap map = new HashMap();
-        map.put("3", "three");
-        map.put("4", "four");
+    @SuppressWarnings("unchecked")
+    public Map<K, V> buildTwo() {
+        HashMap<K, V> map = new HashMap<K, V>();
+        map.put((K) "3", (V) "three");
+        map.put((K) "4", (V) "four");
         return map;
     }
     
     public void testGet() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo());
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
         Assert.assertEquals("one", map.get("1"));
         Assert.assertEquals("four", map.get("4"));
     }
     
+    @SuppressWarnings("unchecked")
     public void testAddComposited() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo());
-        HashMap three = new HashMap();
-        three.put("5", "five");
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+        HashMap<K, V> three = new HashMap<K, V>();
+        three.put((K) "5", (V) "five");
         map.addComposited(three);
         assertTrue(map.containsKey("5"));
         try {
@@ -96,10 +99,11 @@
         }
     }
     
+    @SuppressWarnings("unchecked")
     public void testRemoveComposited() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo());
-        HashMap three = new HashMap();
-        three.put("5", "five");
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+        HashMap<K, V> three = new HashMap<K, V>();
+        three.put((K) "5", (V) "five");
         map.addComposited(three);
         assertTrue(map.containsKey("5"));
         
@@ -111,10 +115,11 @@
         
     }
     
+    @SuppressWarnings("unchecked")
     public void testRemoveFromUnderlying() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo());
-        HashMap three = new HashMap();
-        three.put("5", "five");
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+        HashMap<K, V> three = new HashMap<K, V>();
+        three.put((K) "5", (V) "five");
         map.addComposited(three);
         assertTrue(map.containsKey("5"));
         
@@ -123,10 +128,11 @@
         assertFalse(map.containsKey("5"));
     }
     
+    @SuppressWarnings("unchecked")
     public void testRemoveFromComposited() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo());
-        HashMap three = new HashMap();
-        three.put("5", "five");
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+        HashMap<K, V> three = new HashMap<K, V>();
+        three.put((K) "5", (V) "five");
         map.addComposited(three);
         assertTrue(map.containsKey("5"));
         
@@ -136,21 +142,21 @@
     }
     
     public void testResolveCollision() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo(), 
-            new CompositeMap.MapMutator() {
-            public void resolveCollision(CompositeMap composite,
-            Map existing,
-            Map added,
-            Collection intersect) {
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo(), 
+            new CompositeMap.MapMutator<K, V>() {
+            public void resolveCollision(CompositeMap<K, V> composite,
+            Map<K, V> existing,
+            Map<K, V> added,
+            Collection<K> intersect) {
                 pass = true;
             }
             
-            public Object put(CompositeMap map, Map[] composited, Object key, 
-                Object value) {
+            public V put(CompositeMap<K, V> map, Map<K, V>[] composited, K key, 
+                V value) {
                 throw new UnsupportedOperationException();
             }
             
-            public void putAll(CompositeMap map, Map[] composited, Map t) {
+            public void putAll(CompositeMap<K, V> map, Map<K, V>[] composited, Map<? extends K, ? extends V> t) {
                 throw new UnsupportedOperationException();
             }
         });
@@ -159,47 +165,48 @@
         assertTrue(pass);
     }
     
+    @SuppressWarnings("unchecked")
     public void testPut() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo(), 
-            new CompositeMap.MapMutator() {
-            public void resolveCollision(CompositeMap composite,
-            Map existing,
-            Map added,
-            Collection intersect) {
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo(), 
+            new CompositeMap.MapMutator<K, V>() {
+            public void resolveCollision(CompositeMap<K, V> composite,
+            Map<K, V> existing,
+            Map<K, V> added,
+            Collection<K> intersect) {
                 throw new UnsupportedOperationException();
             }
             
-            public Object put(CompositeMap map, Map[] composited, Object key, 
-                Object value) {
+            public V put(CompositeMap<K, V> map, Map<K, V>[] composited, K key, 
+                V value) {
                 pass = true;
-                return "foo";
+                return (V) "foo";
             }
             
-            public void putAll(CompositeMap map, Map[] composited, Map t) {
+            public void putAll(CompositeMap<K, V> map, Map<K, V>[] composited, Map<? extends K, ? extends V> t) {
                 throw new UnsupportedOperationException();
             }
         });
         
-        map.put("willy", "wonka");
+        map.put((K) "willy", (V) "wonka");
         assertTrue(pass);
     }
     
     public void testPutAll() {
-        CompositeMap map = new CompositeMap(buildOne(), buildTwo(), 
-            new CompositeMap.MapMutator() {
-            public void resolveCollision(CompositeMap composite,
-            Map existing,
-            Map added,
-            Collection intersect) {
+        CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo(), 
+            new CompositeMap.MapMutator<K, V>() {
+            public void resolveCollision(CompositeMap<K, V> composite,
+            Map<K, V> existing,
+            Map<K, V> added,
+            Collection<K> intersect) {
                 throw new UnsupportedOperationException();
             }
             
-            public Object put(CompositeMap map, Map[] composited, Object key,
-                Object value) {
+            public V put(CompositeMap<K, V> map, Map<K, V>[] composited, K key, 
+                V value) {
                 throw new UnsupportedOperationException();
             }
             
-            public void putAll(CompositeMap map, Map[] composited, Map t) {
+            public void putAll(CompositeMap<K, V> map, Map<K, V>[] composited, Map<? extends K, ? extends V> t) {
                 pass = true;
             }
         });