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

svn commit: r815139 - /commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestPredicatedSet.java

Author: bayard
Date: Tue Sep 15 05:57:49 2009
New Revision: 815139

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

    ------------------------------------------------------------------------
    r471202 | scolebourne | 2006-11-04 06:21:44 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Remove getCollection() - use covariant decorated()
    ------------------------------------------------------------------------

Modified:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestPredicatedSet.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestPredicatedSet.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestPredicatedSet.java?rev=815139&r1=815138&r2=815139&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestPredicatedSet.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestPredicatedSet.java Tue Sep 15 05:57:49 2009
@@ -23,7 +23,7 @@
 import junit.framework.TestSuite;
 
 import org.apache.commons.collections.Predicate;
-import org.apache.commons.collections.PredicateUtils;
+import org.apache.commons.collections.functors.TruePredicate;
 
 /**
  * Extension of {@link AbstractTestSet} for exercising the 
@@ -34,90 +34,92 @@
  *
  * @author Phil Steitz
  */
-public class TestPredicatedSet extends AbstractTestSet{
-    
+public class TestPredicatedSet<E> extends AbstractTestSet<E> {
+
     public TestPredicatedSet(String testName) {
         super(testName);
     }
-    
+
     public static Test suite() {
         return new TestSuite(TestPredicatedSet.class);
     }
-    
+
     public static void main(String args[]) {
         String[] testCaseName = { TestPredicatedSet.class.getName()};
         junit.textui.TestRunner.main(testCaseName);
     }
-    
+
  //-------------------------------------------------------------------
-    
-    protected Predicate truePredicate = PredicateUtils.truePredicate();
-    
-    protected Set decorateSet(Set set, Predicate predicate) {
-        return PredicatedSet.decorate(set, predicate);
-    }
-    
-    public Set makeEmptySet() {
-        return decorateSet(new HashSet(), truePredicate);
-    }
-    
-    public Object[] getFullElements() {
-        return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
-    }
-    
-//--------------------------------------------------------------------   
-    
-    protected Predicate testPredicate =  
-        new Predicate() {
-            public boolean evaluate(Object o) {
+
+    protected Predicate<E> truePredicate = TruePredicate.<E>truePredicate();
+
+    protected PredicatedSet<E> decorateSet(Set<E> set, Predicate<? super E> predicate) {
+        return (PredicatedSet<E>) PredicatedSet.decorate(set, predicate);
+    }
+
+    public PredicatedSet<E> makeObject() {
+        return decorateSet(new HashSet<E>(), truePredicate);
+    }
+
+    @SuppressWarnings("unchecked")
+    public E[] getFullElements() {
+        return (E[]) new Object[] {"1", "3", "5", "7", "2", "4", "6"};
+    }
+
+//--------------------------------------------------------------------
+
+    protected Predicate<E> testPredicate =
+        new Predicate<E>() {
+            public boolean evaluate(E o) {
                 return o instanceof String;
             }
-        };      
-    
-    protected Set makeTestSet() {
-        return decorateSet(new HashSet(), testPredicate);
+        };
+
+    protected PredicatedSet<E> makeTestSet() {
+        return decorateSet(new HashSet<E>(), testPredicate);
     }
-    
+
     public void testGetSet() {
-         Set set = makeTestSet();
-        assertTrue("returned set should not be null",
-            ((PredicatedSet) set).getSet() != null);
+        PredicatedSet<E> set = makeTestSet();
+        assertTrue("returned set should not be null", set.decorated() != null);
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testIllegalAdd() {
-        Set set = makeTestSet();
+        Set<E> set = makeTestSet();
         Integer i = new Integer(3);
         try {
-            set.add(i);
+            set.add((E) i);
             fail("Integer should fail string predicate.");
         } catch (IllegalArgumentException e) {
             // expected
         }
-        assertTrue("Collection shouldn't contain illegal element", 
-         !set.contains(i));   
+        assertTrue("Collection shouldn't contain illegal element",
+         !set.contains(i));
     }
 
+    @SuppressWarnings("unchecked")
     public void testIllegalAddAll() {
-        Set set = makeTestSet();
-        Set elements = new HashSet();
-        elements.add("one");
-        elements.add("two");
-        elements.add(new Integer(3));
-        elements.add("four");
+        Set<E> set = makeTestSet();
+        Set<E> elements = new HashSet<E>();
+        elements.add((E) "one");
+        elements.add((E) "two");
+        elements.add((E) new Integer(3));
+        elements.add((E) "four");
         try {
             set.addAll(elements);
             fail("Integer should fail string predicate.");
         } catch (IllegalArgumentException e) {
             // expected
         }
-        assertTrue("Set shouldn't contain illegal element", 
-         !set.contains("one"));   
-        assertTrue("Set shouldn't contain illegal element", 
-         !set.contains("two"));   
-        assertTrue("Set shouldn't contain illegal element", 
-         !set.contains(new Integer(3)));   
-        assertTrue("Set shouldn't contain illegal element", 
-         !set.contains("four"));   
+        assertTrue("Set shouldn't contain illegal element",
+         !set.contains("one"));
+        assertTrue("Set shouldn't contain illegal element",
+         !set.contains("two"));
+        assertTrue("Set shouldn't contain illegal element",
+         !set.contains(new Integer(3)));
+        assertTrue("Set shouldn't contain illegal element",
+         !set.contains("four"));
     }
 
     public String getCompatibilityVersion() {
@@ -131,4 +133,4 @@
 //        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/PredicatedSet.fullCollection.version3.1.obj");
 //    }
 
-}
\ No newline at end of file
+}