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:36 UTC

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

Author: bayard
Date: Tue Sep 15 05:57:36 2009
New Revision: 815131

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

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedMap.java?rev=815131&r1=815130&r2=815131&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedMap.java Tue Sep 15 05:57:36 2009
@@ -23,8 +23,9 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.Predicate;
-import org.apache.commons.collections.PredicateUtils;
+import org.apache.commons.collections.functors.TruePredicate;
 
 /**
  * Extension of {@link AbstractTestMap} for exercising the 
@@ -35,66 +36,68 @@
  *
  * @author Phil Steitz
  */
-public class TestPredicatedMap extends AbstractTestMap{
-    
-    protected static final Predicate truePredicate = PredicateUtils.truePredicate();
-    protected static final Predicate testPredicate = new Predicate() {
+public class TestPredicatedMap<K, V> extends AbstractTestIterableMap<K, V> {
+
+    protected static final Predicate<Object> truePredicate = TruePredicate.<Object>truePredicate();
+
+    protected static final Predicate<Object> testPredicate = new Predicate<Object>() {
         public boolean evaluate(Object o) {
             return (o instanceof String);
         }
     };
-    
-    
+
     public TestPredicatedMap(String testName) {
         super(testName);
     }
-    
+
     public static Test suite() {
         return new TestSuite(TestPredicatedMap.class);
     }
-    
+
     public static void main(String args[]) {
         String[] testCaseName = { TestPredicatedMap.class.getName()};
         junit.textui.TestRunner.main(testCaseName);
     }
 
     //-----------------------------------------------------------------------
-    protected Map decorateMap(Map map, Predicate keyPredicate, 
-        Predicate valuePredicate) {
+    protected IterableMap<K, V> decorateMap(Map<K, V> map, Predicate<? super K> keyPredicate,
+        Predicate<? super V> valuePredicate) {
         return PredicatedMap.decorate(map, keyPredicate, valuePredicate);
     }
-    
-    public Map makeEmptyMap() {
-        return decorateMap(new HashMap(), truePredicate, truePredicate);
-    }
-    
-    public Map makeTestMap() {
-        return decorateMap(new HashMap(), testPredicate, testPredicate);
+
+    public IterableMap<K, V> makeObject() {
+        return decorateMap(new HashMap<K, V>(), truePredicate, truePredicate);
+    }
+
+    public IterableMap<K, V> makeTestMap() {
+        return decorateMap(new HashMap<K, V>(), testPredicate, testPredicate);
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testEntrySet() {
-        Map map = makeTestMap();
+        Map<K, V> map = makeTestMap();
         assertTrue("returned entryset should not be null",
             map.entrySet() != null);
-        map = decorateMap(new HashMap(), null, null);
-        map.put("oneKey", "oneValue");
+        map = decorateMap(new HashMap<K, V>(), null, null);
+        map.put((K) "oneKey", (V) "oneValue");
         assertTrue("returned entryset should contain one entry",
-            map.entrySet().size() == 1); 
+            map.entrySet().size() == 1);
         map = decorateMap(map, null, null);
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testPut() {
-        Map map = makeTestMap();
+        Map<K, V> map = makeTestMap();
         try {
-            map.put("Hi", new Integer(3));
+            map.put((K) "Hi", (V) new Integer(3));
             fail("Illegal value should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
         }
 
         try {
-            map.put(new Integer(3), "Hi");
+            map.put((K) new Integer(3), (V) "Hi");
             fail("Illegal key should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
@@ -103,11 +106,11 @@
         assertTrue(!map.containsKey(new Integer(3)));
         assertTrue(!map.containsValue(new Integer(3)));
 
-        Map map2 = new HashMap();
-        map2.put("A", "a");
-        map2.put("B", "b");
-        map2.put("C", "c");
-        map2.put("c", new Integer(3));
+        Map<K, V> map2 = new HashMap<K, V>();
+        map2.put((K) "A", (V) "a");
+        map2.put((K) "B", (V) "b");
+        map2.put((K) "C", (V) "c");
+        map2.put((K) "c", (V) new Integer(3));
 
         try {
             map.putAll(map2);
@@ -116,21 +119,21 @@
             // expected
         }
 
-        map.put("E", "e");
-        Iterator iterator = map.entrySet().iterator();
+        map.put((K) "E", (V) "e");
+        Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
         try {
-            Map.Entry entry = (Map.Entry)iterator.next();
-            entry.setValue(new Integer(3));
+            Map.Entry<K, V> entry = iterator.next();
+            entry.setValue((V) new Integer(3));
             fail("Illegal value should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
         }
-        
-        map.put("F", "f");
+
+        map.put((K) "F", (V) "f");
         iterator = map.entrySet().iterator();
-        Map.Entry entry = (Map.Entry)iterator.next();
-        entry.setValue("x");
-        
+        Map.Entry<K, V> entry = iterator.next();
+        entry.setValue((V) "x");
+
     }
 
     public String getCompatibilityVersion() {
@@ -147,4 +150,4 @@
 //            (java.io.Serializable) map,
 //            "D:/dev/collections/data/test/PredicatedMap.fullCollection.version3.1.obj");
 //    }
-}
\ No newline at end of file
+}