commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skes...@apache.org
Subject svn commit: r643795 - in /commons/proper/collections/branches/collections_jdk5_branch: ./ src/java/org/apache/commons/collections/ src/java/org/apache/commons/collections/functors/ src/test/org/apache/commons/collections/ src/test/org/apache/commons/co...
Date Wed, 02 Apr 2008 08:50:04 GMT
Author: skestle
Date: Wed Apr  2 01:49:57 2008
New Revision: 643795

URL: http://svn.apache.org/viewvc?rev=643795&view=rev
Log:
Generified EqualPredicate and created individual test class moved from TestPredicateUtils

Added assertFalse() and assertTrue to BasicPredicateTestBase with (Predicate, Object) parameters

Issues: COLLECTIONS-243, COLLECTIONS-253, COLLECTIONS-293

Added:
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java
Modified:
    commons/proper/collections/branches/collections_jdk5_branch/   (props changed)
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ClosureUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/PredicateUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/TransformerUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/EqualPredicate.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/NullPredicate.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestAllPackages.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestClosureUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestPredicateUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestTransformerUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestAll.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestNullPredicate.java

Propchange: commons/proper/collections/branches/collections_jdk5_branch/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Apr  2 01:49:57 2008
@@ -18,3 +18,4 @@
 clirr*.txt
 commons-collections*.jar*
 collections.iml
+TEST-org.apache.commons.collections*

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ClosureUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ClosureUtils.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ClosureUtils.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ClosureUtils.java
Wed Apr  2 01:49:57 2008
@@ -360,7 +360,7 @@
         int i = 0;
         for (Iterator it = objectsAndClosures.entrySet().iterator(); it.hasNext();) {
             Map.Entry entry = (Map.Entry) it.next();
-            preds[i] = EqualPredicate.getInstance(entry.getKey());
+            preds[i] = EqualPredicate.equalPredicate(entry.getKey());
             trs[i] = (Closure) entry.getValue();
             i++;
         }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/PredicateUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/PredicateUtils.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/PredicateUtils.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/PredicateUtils.java
Wed Apr  2 01:49:57 2008
@@ -155,9 +155,11 @@
      * 
      * @param value  the value to compare against
      * @return the predicate
+     * @deprecated use {@link EqualPredicate#equalPredicate(Object)} instead.
      */
-    public static Predicate equalPredicate(Object value) {
-        return EqualPredicate.getInstance(value);
+    @Deprecated
+    public static <T> Predicate<T> equalPredicate(T value) {
+        return EqualPredicate.equalPredicate(value);
     }
 
     /**

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/TransformerUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/TransformerUtils.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/TransformerUtils.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/TransformerUtils.java
Wed Apr  2 01:49:57 2008
@@ -341,7 +341,7 @@
         int i = 0;
         for (Iterator it = objectsAndTransformers.entrySet().iterator(); it.hasNext();) {
             Map.Entry entry = (Map.Entry) it.next();
-            preds[i] = EqualPredicate.getInstance(entry.getKey());
+            preds[i] = EqualPredicate.equalPredicate(entry.getKey());
             trs[i] = (Transformer) entry.getValue();
             i++;
         }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/EqualPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/EqualPredicate.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/EqualPredicate.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/EqualPredicate.java
Wed Apr  2 01:49:57 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.collections.functors;
 
+import static org.apache.commons.collections.functors.NullPredicate.nullPredicate;
+
 import java.io.Serializable;
 
 import org.apache.commons.collections.Predicate;
@@ -29,7 +31,7 @@
  *
  * @author Stephen Colebourne
  */
-public final class EqualPredicate implements Predicate, Serializable {
+public final class EqualPredicate<T> implements Predicate<T>, Serializable {
 
     /** Serial version UID */
     private static final long serialVersionUID = 5633766978029907089L;
@@ -43,12 +45,28 @@
      * @param object  the object to compare to
      * @return the predicate
      * @throws IllegalArgumentException if the predicate is null
+     * @deprecated use {@link #equalPredicate(Object)} instead.
+     */
+    @Deprecated
+    public static <T> Predicate<T> getInstance(T object) {
+        if (object == null) {
+            return nullPredicate();
+        }
+        return new EqualPredicate<T>(object);
+    }
+
+    /**
+     * Factory to create the identity predicate.
+     * 
+     * @param object  the object to compare to
+     * @return the predicate
+     * @throws IllegalArgumentException if the predicate is null
      */
-    public static Predicate getInstance(Object object) {
+    public static <T, O extends T> Predicate<T> equalPredicate(O object) {
         if (object == null) {
-            return NullPredicate.INSTANCE;
+            return nullPredicate();
         }
-        return new EqualPredicate(object);
+        return new EqualPredicate<T>(object);
     }
 
     /**

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/NullPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/NullPredicate.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/NullPredicate.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/functors/NullPredicate.java
Wed Apr  2 01:49:57 2008
@@ -41,6 +41,18 @@
      * 
      * @return the singleton instance
      * @since Commons Collections 3.1
+     * @deprecated use {@link #nullPredicate()} instead.
+     */
+    @Deprecated
+    public static <T> Predicate<T> getInstance() {
+        return nullPredicate();
+    }
+
+    /**
+     * Factory returning the singleton instance.
+     * 
+     * @return the singleton instance
+     * @since Commons Collections 3.1
      */
     @SuppressWarnings("unchecked")
     public static <T> Predicate<T> nullPredicate() {

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestAllPackages.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestAllPackages.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestAllPackages.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestAllPackages.java
Wed Apr  2 01:49:57 2008
@@ -36,6 +36,7 @@
     org.apache.commons.collections.buffer.TestAll.class,
     org.apache.commons.collections.collection.TestAll.class,
     org.apache.commons.collections.comparators.TestAll.class,
+    org.apache.commons.collections.functors.TestAll.class,
     org.apache.commons.collections.iterators.TestAll.class,
     org.apache.commons.collections.keyvalue.TestAll.class,
     org.apache.commons.collections.list.TestAll.class,

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestClosureUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestClosureUtils.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestClosureUtils.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestClosureUtils.java
Wed Apr  2 01:49:57 2008
@@ -26,6 +26,7 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
+import org.apache.commons.collections.functors.EqualPredicate;
 import org.apache.commons.collections.functors.NOPClosure;
 
 /**
@@ -276,7 +277,7 @@
         MockClosure a = new MockClosure();
         MockClosure b = new MockClosure();
         ClosureUtils.switchClosure(
-            new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")},

+            new Predicate[] {EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},

             new Closure[] {a, b}).execute("WELL");
         assertEquals(0, a.count);
         assertEquals(0, b.count);
@@ -284,7 +285,7 @@
         a = new MockClosure();
         b = new MockClosure();
         ClosureUtils.switchClosure(
-            new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")},

+            new Predicate[] {EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},

             new Closure[] {a, b}).execute("HELLO");
         assertEquals(1, a.count);
         assertEquals(0, b.count);
@@ -293,7 +294,7 @@
         b = new MockClosure();
         MockClosure c = new MockClosure();
         ClosureUtils.switchClosure(
-            new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")},

+            new Predicate[] {EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},

             new Closure[] {a, b}, c).execute("WELL");
         assertEquals(0, a.count);
         assertEquals(0, b.count);
@@ -302,8 +303,8 @@
         a = new MockClosure();
         b = new MockClosure();
         Map map = new HashMap();
-        map.put(PredicateUtils.equalPredicate("HELLO"), a);
-        map.put(PredicateUtils.equalPredicate("THERE"), b);
+        map.put(EqualPredicate.equalPredicate("HELLO"), a);
+        map.put(EqualPredicate.equalPredicate("THERE"), b);
         ClosureUtils.switchClosure(map).execute(null);
         assertEquals(0, a.count);
         assertEquals(0, b.count);
@@ -311,8 +312,8 @@
         a = new MockClosure();
         b = new MockClosure();
         map = new HashMap();
-        map.put(PredicateUtils.equalPredicate("HELLO"), a);
-        map.put(PredicateUtils.equalPredicate("THERE"), b);
+        map.put(EqualPredicate.equalPredicate("HELLO"), a);
+        map.put(EqualPredicate.equalPredicate("THERE"), b);
         ClosureUtils.switchClosure(map).execute("THERE");
         assertEquals(0, a.count);
         assertEquals(1, b.count);
@@ -321,8 +322,8 @@
         b = new MockClosure();
         c = new MockClosure();
         map = new HashMap();
-        map.put(PredicateUtils.equalPredicate("HELLO"), a);
-        map.put(PredicateUtils.equalPredicate("THERE"), b);
+        map.put(EqualPredicate.equalPredicate("HELLO"), a);
+        map.put(EqualPredicate.equalPredicate("THERE"), b);
         map.put(null, c);
         ClosureUtils.switchClosure(map).execute("WELL");
         assertEquals(0, a.count);

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestCollectionUtils.java
Wed Apr  2 01:49:57 2008
@@ -17,6 +17,7 @@
 package org.apache.commons.collections;
 
 import static junit.framework.Assert.assertFalse;
+import static org.apache.commons.collections.functors.EqualPredicate.equalPredicate;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -30,6 +31,7 @@
 import org.apache.commons.collections.collection.SynchronizedCollection;
 import org.apache.commons.collections.collection.TransformedCollection;
 import org.apache.commons.collections.collection.UnmodifiableCollection;
+import org.apache.commons.collections.functors.EqualPredicate;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -486,10 +488,10 @@
 
     @Test
     public void find() {
-        Predicate<Number> testPredicate = PredicateUtils.equalPredicate(4);
+        Predicate<Number> testPredicate = equalPredicate(4);
         Integer test = CollectionUtils.find(collectionA, testPredicate);
         assertTrue(test.equals(4));
-        testPredicate = PredicateUtils.equalPredicate(45);
+        testPredicate = equalPredicate(45);
         test = CollectionUtils.find(collectionA, testPredicate);
         assertTrue(test == null);
         assertEquals(CollectionUtils.find(null, testPredicate), null);

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestPredicateUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestPredicateUtils.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestPredicateUtils.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestPredicateUtils.java
Wed Apr  2 01:49:57 2008
@@ -17,11 +17,10 @@
 package org.apache.commons.collections;
 
 import static org.apache.commons.collections.functors.NullPredicate.nullPredicate;
+import static org.apache.commons.collections.functors.TruePredicate.truePredicate;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
@@ -32,7 +31,8 @@
 import java.util.Map;
 
 import org.apache.commons.collections.functors.BasicPredicateTestBase;
-import org.apache.commons.collections.functors.NullPredicate;
+import org.apache.commons.collections.functors.EqualPredicate;
+import org.apache.commons.collections.functors.TruePredicate;
 import org.junit.Test;
 
 /**
@@ -87,18 +87,6 @@
         assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cInteger));
     }
 
-    // equalPredicate
-    //------------------------------------------------------------------
-
-    @Test public void testEqualPredicate() {
-        assertSame(nullPredicate(), PredicateUtils.equalPredicate(null));
-        assertNotNull(PredicateUtils.equalPredicate(new Integer(6)));
-        assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(null));
-        assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cObject));
-        assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cString));
-        assertEquals(true, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cInteger));
-    }
-
     // identityPredicate
     //------------------------------------------------------------------
 
@@ -180,7 +168,7 @@
 
     @Test public void testAllPredicate() {
         assertTrue(PredicateUtils.allPredicate(
-            new Predicate[] {}).evaluate(null));
+            new Predicate[] {}), null);
         assertEquals(true, PredicateUtils.allPredicate(new Predicate[] {
             PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null));
         assertEquals(false, PredicateUtils.allPredicate(new Predicate[] {
@@ -211,12 +199,12 @@
         assertEquals(false, PredicateUtils.allPredicate(coll).evaluate(null));
         coll.clear();
         coll.add(PredicateUtils.falsePredicate());
-        assertFalse(PredicateUtils.allPredicate(coll).evaluate(null));
+        assertFalse(PredicateUtils.allPredicate(coll), null);
         coll.clear();
         coll.add(PredicateUtils.truePredicate());
-        assertTrue(PredicateUtils.allPredicate(coll).evaluate(null));
+        assertTrue(PredicateUtils.allPredicate(coll), null);
         coll.clear();
-        assertTrue(PredicateUtils.allPredicate(coll).evaluate(null));
+        assertTrue(PredicateUtils.allPredicate(coll), null);
     }
 
     @Test public void testAllPredicateEx1() {
@@ -295,7 +283,7 @@
 
     @Test public void testAnyPredicate() {
         assertFalse(PredicateUtils.anyPredicate(
-            new Predicate[] {}).evaluate(null));
+            new Predicate[] {}), null);
         assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] {
             PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null));
         assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] {
@@ -326,12 +314,12 @@
         assertEquals(false, PredicateUtils.anyPredicate(coll).evaluate(null));
         coll.clear();
         coll.add(PredicateUtils.falsePredicate());
-        assertFalse(PredicateUtils.anyPredicate(coll).evaluate(null));
+        assertFalse(PredicateUtils.anyPredicate(coll), null);
         coll.clear();
         coll.add(PredicateUtils.truePredicate());
-        assertTrue(PredicateUtils.anyPredicate(coll).evaluate(null));
+        assertTrue(PredicateUtils.anyPredicate(coll), null);
         coll.clear();
-        assertFalse(PredicateUtils.anyPredicate(coll).evaluate(null));
+        assertFalse(PredicateUtils.anyPredicate(coll), null);
     }
 
     @Test public void testAnyPredicateEx1() {
@@ -409,8 +397,7 @@
     //------------------------------------------------------------------
 
     @Test public void testOnePredicate() {
-        assertFalse(PredicateUtils.onePredicate(
-            new Predicate[] {}).evaluate(null));
+        assertFalse(PredicateUtils.onePredicate(new Predicate[] {}), null);
         assertEquals(false, PredicateUtils.onePredicate(new Predicate[] {
             PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null));
         assertEquals(false, PredicateUtils.onePredicate(new Predicate[] {
@@ -445,12 +432,12 @@
         assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null));
         coll.clear();
         coll.add(PredicateUtils.falsePredicate());
-        assertFalse(PredicateUtils.onePredicate(coll).evaluate(null));
+        assertFalse(PredicateUtils.onePredicate(coll), null);
         coll.clear();
         coll.add(PredicateUtils.truePredicate());
-        assertTrue(PredicateUtils.onePredicate(coll).evaluate(null));
+        assertTrue(PredicateUtils.onePredicate(coll), null);
         coll.clear();
-        assertFalse(PredicateUtils.onePredicate(coll).evaluate(null));
+        assertFalse(PredicateUtils.onePredicate(coll), null);
     }
 
     @Test public void testOnePredicateEx1() {
@@ -528,8 +515,7 @@
     //------------------------------------------------------------------
 
     @Test public void testNonePredicate() {
-        assertTrue(PredicateUtils.nonePredicate(
-            new Predicate[] {}).evaluate(null));
+        assertTrue(PredicateUtils.nonePredicate(new Predicate[] {}), null);
         assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] {
             PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null));
         assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] {
@@ -560,12 +546,12 @@
         assertEquals(true, PredicateUtils.nonePredicate(coll).evaluate(null));
         coll.clear();
         coll.add(PredicateUtils.falsePredicate());
-        assertTrue(PredicateUtils.nonePredicate(coll).evaluate(null));
+        assertTrue(PredicateUtils.nonePredicate(coll), null);
         coll.clear();
         coll.add(PredicateUtils.truePredicate());
-        assertFalse(PredicateUtils.nonePredicate(coll).evaluate(null));
+        assertFalse(PredicateUtils.nonePredicate(coll), null);
         coll.clear();
-        assertTrue(PredicateUtils.nonePredicate(coll).evaluate(null));
+        assertTrue(PredicateUtils.nonePredicate(coll), null);
     }
 
     @Test public void testNonePredicateEx1() {
@@ -816,13 +802,18 @@
         Map map = new HashMap();
         map.put(Boolean.TRUE, "Hello");
         Transformer t = TransformerUtils.mapTransformer(map);
-        Predicate p = PredicateUtils.equalPredicate("Hello");
+        Predicate p = EqualPredicate.equalPredicate("Hello");
         assertEquals(false, PredicateUtils.transformedPredicate(t, p).evaluate(null));
         assertEquals(true, PredicateUtils.transformedPredicate(t, p).evaluate(Boolean.TRUE));
         try {
             PredicateUtils.transformedPredicate(null, null);
             fail();
         } catch (IllegalArgumentException ex) {}
+    }
+
+    @Override
+    protected Predicate<?> generatePredicate() {
+        return truePredicate();  //Just return something to satisfy super class.
     }
 
 }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestTransformerUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestTransformerUtils.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestTransformerUtils.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestTransformerUtils.java
Wed Apr  2 01:49:57 2008
@@ -29,6 +29,7 @@
 import junit.textui.TestRunner;
 
 import org.apache.commons.collections.functors.ConstantTransformer;
+import org.apache.commons.collections.functors.EqualPredicate;
 import org.apache.commons.collections.functors.NOPTransformer;
 
 /**
@@ -266,22 +267,22 @@
         assertEquals("B", TransformerUtils.switchTransformer(PredicateUtils.falsePredicate(),
a, b).transform(null));
         
         assertEquals(null, TransformerUtils.switchTransformer(
-            new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")},

+            new Predicate[] {EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},

             new Transformer[] {a, b}).transform("WELL"));
         assertEquals("A", TransformerUtils.switchTransformer(
-            new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")},

+            new Predicate[] {EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},

             new Transformer[] {a, b}).transform("HELLO"));
         assertEquals("B", TransformerUtils.switchTransformer(
-            new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")},

+            new Predicate[] {EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},

             new Transformer[] {a, b}).transform("THERE"));
             
         assertEquals("C", TransformerUtils.switchTransformer(
-            new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")},

+            new Predicate[] {EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE")},

             new Transformer[] {a, b}, c).transform("WELL"));
             
         Map map = new HashMap();
-        map.put(PredicateUtils.equalPredicate("HELLO"), a);
-        map.put(PredicateUtils.equalPredicate("THERE"), b);
+        map.put(EqualPredicate.equalPredicate("HELLO"), a);
+        map.put(EqualPredicate.equalPredicate("THERE"), b);
         assertEquals(null, TransformerUtils.switchTransformer(map).transform("WELL"));
         assertEquals("A", TransformerUtils.switchTransformer(map).transform("HELLO"));
         assertEquals("B", TransformerUtils.switchTransformer(map).transform("THERE"));

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java
Wed Apr  2 01:49:57 2008
@@ -1,8 +1,11 @@
 package org.apache.commons.collections.functors;
 
+import org.apache.commons.collections.Predicate;
+import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Test;
 
-public class BasicPredicateTestBase {
+public abstract class BasicPredicateTestBase {
     protected Object cObject;
     protected String cString;
     protected Integer cInteger;
@@ -12,5 +15,24 @@
         cObject = new Object();
         cString = "Hello";
         cInteger = new Integer(6);
+    }
+    
+    @Test
+    public void predicateSanityTests() throws Exception {
+        Predicate<?> predicate = generatePredicate();
+        Assert.assertNotNull(predicate);
+    }
+
+    /**
+     * @return a predicate for general sanity tests.
+     */
+    protected abstract Predicate<?> generatePredicate();
+
+    protected <T> void assertFalse(Predicate<T> predicate, T testObject) {
+        Assert.assertFalse(predicate.evaluate(testObject));
+    }
+
+    protected <T> void assertTrue(Predicate<T> predicate, T testObject) {
+        Assert.assertTrue(predicate.evaluate(testObject));
     }
 }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestAll.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestAll.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestAll.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestAll.java
Wed Apr  2 01:49:57 2008
@@ -14,7 +14,8 @@
  * @author Edwin Tellman
  */
 @RunWith(Suite.class)
-@SuiteClasses({TestAllPredicate.class, 
+@SuiteClasses({TestAllPredicate.class,
+    TestEqualPredicate.class,
     TestNullPredicate.class})
 public class TestAll extends TestCase {
 }

Added: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java?rev=643795&view=auto
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java
(added)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java
Wed Apr  2 01:49:57 2008
@@ -0,0 +1,50 @@
+package org.apache.commons.collections.functors;
+
+import static org.apache.commons.collections.functors.EqualPredicate.equalPredicate;
+import static org.apache.commons.collections.functors.NullPredicate.nullPredicate;
+import static org.junit.Assert.assertSame;
+
+import org.apache.commons.collections.Predicate;
+import org.junit.Test;
+
+
+public class TestEqualPredicate extends BasicPredicateTestBase {
+    private static final EqualsTestObject FALSE_OBJECT = new EqualsTestObject(false);
+    private static final EqualsTestObject TRUE_OBJECT = new EqualsTestObject(true);
+
+    @Override
+    protected Predicate<?> generatePredicate() {
+       return equalPredicate(null);
+    }
+    
+    @Test
+    public void testNullArgumentEqualsNullPredicate() throws Exception {
+        assertSame(nullPredicate(), equalPredicate(null));
+    }
+    
+    @Test
+    public void objectFactoryUsesEqualsForTest() throws Exception {
+        Predicate<EqualsTestObject> predicate = equalPredicate(FALSE_OBJECT);
+        assertFalse(predicate, FALSE_OBJECT);
+        assertTrue(equalPredicate(TRUE_OBJECT), TRUE_OBJECT);
+    }
+    
+    @Test
+    public void testPredicateTypeCanBeSuperClassOfObject() throws Exception {
+        Predicate<Number> predicate = equalPredicate(4);
+        assertTrue(predicate, 4);
+    }
+
+    public static class EqualsTestObject {
+        private final boolean b;
+
+        public EqualsTestObject(boolean b) {
+            this.b = b;
+        }
+        
+        @Override
+        public boolean equals(Object obj) {
+            return b;
+        }
+    }
+}

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestNullPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestNullPredicate.java?rev=643795&r1=643794&r2=643795&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestNullPredicate.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/functors/TestNullPredicate.java
Wed Apr  2 01:49:57 2008
@@ -1,9 +1,7 @@
 package org.apache.commons.collections.functors;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.apache.commons.collections.functors.NullPredicate.nullPredicate;
+import static org.junit.Assert.assertSame;
 
 import org.apache.commons.collections.Predicate;
 import org.junit.Test;
@@ -12,14 +10,17 @@
 public class TestNullPredicate extends BasicPredicateTestBase {
     @Test
     public void testNullPredicate() {
-        assertNotNull(NullPredicate.nullPredicate());
-        assertEquals(NullPredicate.nullPredicate(), NullPredicate.nullPredicate());
-        assertTrue(NullPredicate.nullPredicate().evaluate(null));
+        assertSame(NullPredicate.nullPredicate(), NullPredicate.nullPredicate());
+        assertTrue(nullPredicate(), null);
     }
     
     public void ensurePredicateCanBeTypedWithoutWarning() throws Exception {
         Predicate<String> predicate = NullPredicate.nullPredicate();
-        predicate.evaluate(null); //Just "use" the predicate for strict compiler settings
-        assertFalse(predicate.evaluate(cString));
+        assertFalse(predicate, cString);
+    }
+
+    @Override
+    protected Predicate<?> generatePredicate() {
+        return nullPredicate();
     }    
 }



Mime
View raw message