commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r815126 - /commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
Date Tue, 15 Sep 2009 05:57:28 GMT
Author: bayard
Date: Tue Sep 15 05:57:27 2009
New Revision: 815126

URL: http://svn.apache.org/viewvc?rev=815126&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/TestDefaultedMap.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestDefaultedMap.java?rev=815126&r1=815125&r2=815126&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
Tue Sep 15 05:57:27 2009
@@ -24,6 +24,7 @@
 
 import org.apache.commons.collections.Factory;
 import org.apache.commons.collections.FactoryUtils;
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.Transformer;
 import org.apache.commons.collections.functors.ConstantFactory;
 
@@ -36,9 +37,9 @@
  *
  * @author Stephen Colebourne
  */
-public class TestDefaultedMap extends AbstractTestMap {
+public class TestDefaultedMap<K, V> extends AbstractTestIterableMap<K, V> {
 
-    protected static final Factory nullFactory = FactoryUtils.nullFactory();
+    protected final Factory<V> nullFactory = FactoryUtils.<V>nullFactory();
 
     public TestDefaultedMap(String testName) {
         super(testName);
@@ -53,20 +54,21 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    //-----------------------------------------------------------------------    
-    public Map makeEmptyMap() {
-        return DefaultedMap.decorate(new HashMap(), nullFactory);
+    //-----------------------------------------------------------------------
+    public IterableMap<K, V> makeObject() {
+        return DefaultedMap.decorate(new HashMap<K, V>(), nullFactory);
     }
 
-    //-----------------------------------------------------------------------    
+    //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testMapGet() {
-        Map map = new DefaultedMap("NULL");
-        
+        Map<K, V> map = new DefaultedMap<K, V>((V) "NULL");
+
         assertEquals(0, map.size());
         assertEquals(false, map.containsKey("NotInMap"));
         assertEquals("NULL", map.get("NotInMap"));
-        
-        map.put("Key", "Value");
+
+        map.put((K) "Key", (V) "Value");
         assertEquals(1, map.size());
         assertEquals(true, map.containsKey("Key"));
         assertEquals("Value", map.get("Key"));
@@ -74,16 +76,17 @@
         assertEquals("NULL", map.get("NotInMap"));
     }
 
+    @SuppressWarnings("unchecked")
     public void testMapGet2() {
-        HashMap base = new HashMap();
-        Map map = DefaultedMap.decorate(base, "NULL");
-        
+        HashMap<K, V> base = new HashMap<K, V>();
+        Map<K, V> map = DefaultedMap.decorate(base, (V) "NULL");
+
         assertEquals(0, map.size());
         assertEquals(0, base.size());
         assertEquals(false, map.containsKey("NotInMap"));
         assertEquals("NULL", map.get("NotInMap"));
-        
-        map.put("Key", "Value");
+
+        map.put((K) "Key", (V) "Value");
         assertEquals(1, map.size());
         assertEquals(1, base.size());
         assertEquals(true, map.containsKey("Key"));
@@ -92,16 +95,17 @@
         assertEquals("NULL", map.get("NotInMap"));
     }
 
+    @SuppressWarnings("unchecked")
     public void testMapGet3() {
-        HashMap base = new HashMap();
-        Map map = DefaultedMap.decorate(base, ConstantFactory.getInstance("NULL"));
-        
+        HashMap<K, V> base = new HashMap<K, V>();
+        Map<K, V> map = DefaultedMap.decorate(base, ConstantFactory.getInstance((V)
"NULL"));
+
         assertEquals(0, map.size());
         assertEquals(0, base.size());
         assertEquals(false, map.containsKey("NotInMap"));
         assertEquals("NULL", map.get("NotInMap"));
-        
-        map.put("Key", "Value");
+
+        map.put((K) "Key", (V) "Value");
         assertEquals(1, map.size());
         assertEquals(1, base.size());
         assertEquals(true, map.containsKey("Key"));
@@ -110,24 +114,25 @@
         assertEquals("NULL", map.get("NotInMap"));
     }
 
+    @SuppressWarnings("unchecked")
     public void testMapGet4() {
-        HashMap base = new HashMap();
-        Map map = DefaultedMap.decorate(base, new Transformer() {
-            public Object transform(Object input) {
+        HashMap<K, V> base = new HashMap<K, V>();
+        Map<K, V> map = DefaultedMap.decorate(base, new Transformer<K, V>() {
+            public V transform(K input) {
                 if (input instanceof String) {
-                    return "NULL";
+                    return (V) "NULL";
                 }
-                return "NULL_OBJECT";
+                return (V) "NULL_OBJECT";
             }
         });
-        
+
         assertEquals(0, map.size());
         assertEquals(0, base.size());
         assertEquals(false, map.containsKey("NotInMap"));
         assertEquals("NULL", map.get("NotInMap"));
         assertEquals("NULL_OBJECT", map.get(new Integer(0)));
-        
-        map.put("Key", "Value");
+
+        map.put((K) "Key", (V) "Value");
         assertEquals(1, map.size());
         assertEquals(1, base.size());
         assertEquals(true, map.containsKey("Key"));



Mime
View raw message