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:56:58 UTC

svn commit: r815110 - /commons/proper/collections/trunk/src/test/org/apache/commons/collections/bag/TestPredicatedSortedBag.java

Author: bayard
Date: Tue Sep 15 05:56:58 2009
New Revision: 815110

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

    ------------------------------------------------------------------------
    r471201 | scolebourne | 2006-11-04 06:17:26 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Remove getBag() - use covariant decorated()
    ------------------------------------------------------------------------

Modified:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/bag/TestPredicatedSortedBag.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/bag/TestPredicatedSortedBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/bag/TestPredicatedSortedBag.java?rev=815110&r1=815109&r2=815110&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/bag/TestPredicatedSortedBag.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/bag/TestPredicatedSortedBag.java Tue Sep 15 05:56:58 2009
@@ -21,10 +21,9 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.commons.collections.Bag;
 import org.apache.commons.collections.Predicate;
-import org.apache.commons.collections.PredicateUtils;
 import org.apache.commons.collections.SortedBag;
+import org.apache.commons.collections.functors.TruePredicate;
 
 /**
  * Extension of {@link AbstractTestSortedBag} for exercising the {@link PredicatedSortedBag}
@@ -35,73 +34,74 @@
  *
  * @author Phil Steitz
  */
-public class TestPredicatedSortedBag extends AbstractTestSortedBag {
-    
-    private SortedBag nullBag = null;
-    
+public class TestPredicatedSortedBag<T> extends AbstractTestSortedBag<T> {
+
+    private SortedBag<T> nullBag = null;
+
     public TestPredicatedSortedBag(String testName) {
         super(testName);
     }
-    
+
     public static Test suite() {
         return new TestSuite(TestPredicatedSortedBag.class);
     }
-    
+
     public static void main(String args[]) {
         String[] testCaseName = { TestPredicatedSortedBag.class.getName()};
         junit.textui.TestRunner.main(testCaseName);
     }
-    
+
     //--------------------------------------------------------------------------
-    
-    protected Predicate stringPredicate() {
-        return new Predicate() {
-            public boolean evaluate(Object o) {
+
+    protected Predicate<T> stringPredicate() {
+        return new Predicate<T>() {
+            public boolean evaluate(T o) {
                 return o instanceof String;
             }
         };
-    }   
-    
-    protected Predicate truePredicate = PredicateUtils.truePredicate();
-    
-    protected SortedBag decorateBag(SortedBag bag, Predicate predicate) {
+    }
+
+    protected Predicate<T> truePredicate = TruePredicate.<T>truePredicate();
+
+    protected SortedBag<T> decorateBag(SortedBag<T> bag, Predicate<T> predicate) {
         return PredicatedSortedBag.decorate(bag, predicate);
     }
-    
-    public Bag makeBag() {
-        return decorateBag(new TreeBag(), truePredicate);
-    }
-    
-    protected Bag makeTestBag() {
-        return decorateBag(new TreeBag(), stringPredicate());
+
+    public SortedBag<T> makeObject() {
+        return decorateBag(new TreeBag<T>(), truePredicate);
+    }
+
+    protected SortedBag<T> makeTestBag() {
+        return decorateBag(new TreeBag<T>(), stringPredicate());
     }
-    
+
     //--------------------------------------------------------------------------
-    
+
     public void testDecorate() {
-        SortedBag bag = decorateBag(new TreeBag(), stringPredicate());
-        SortedBag bag2 = ((PredicatedSortedBag) bag).getSortedBag();
+        SortedBag<T> bag = decorateBag(new TreeBag<T>(), stringPredicate());
+        ((PredicatedSortedBag<T>) bag).decorated();
         try {
-            SortedBag bag3 = decorateBag(new TreeBag(), null);
+            decorateBag(new TreeBag<T>(), null);
             fail("Expecting IllegalArgumentException for null predicate");
         } catch (IllegalArgumentException e) {}
         try {
-            SortedBag bag4 = decorateBag(nullBag, stringPredicate());
+            decorateBag(nullBag, stringPredicate());
             fail("Expecting IllegalArgumentException for null bag");
         } catch (IllegalArgumentException e) {}
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testSortOrder() {
-        SortedBag bag = decorateBag(new TreeBag(), stringPredicate());
+        SortedBag<T> bag = decorateBag(new TreeBag<T>(), stringPredicate());
         String one = "one";
         String two = "two";
         String three = "three";
-        bag.add(one);
-        bag.add(two);
-        bag.add(three);
+        bag.add((T) one);
+        bag.add((T) two);
+        bag.add((T) three);
         assertEquals("first element", bag.first(), one);
-        assertEquals("last element", bag.last(), two); 
-        Comparator c = bag.comparator();
+        assertEquals("last element", bag.last(), two);
+        Comparator<? super T> c = bag.comparator();
         assertTrue("natural order, so comparator should be null", c == null);
     }