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

svn commit: r815113 - /commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/

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

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

    ------------------------------------------------------------------------
    r644140 | skestle | 2008-04-02 19:42:30 -0700 (Wed, 02 Apr 2008) | 1 line
    
    Fixed javac complier generic issues
    ------------------------------------------------------------------------
    r644138 | skestle | 2008-04-02 19:34:09 -0700 (Wed, 02 Apr 2008) | 1 line
    
    Fixed javac complier generic issues
    ------------------------------------------------------------------------
    r643795 | skestle | 2008-04-02 01:49:57 -0700 (Wed, 02 Apr 2008) | 5 lines
    
    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
    ------------------------------------------------------------------------
    r643782 | skestle | 2008-04-02 01:00:00 -0700 (Wed, 02 Apr 2008) | 5 lines
    
    Generified NullPredicate and created individual test class moved on TestPredicateUtils
    
    Renamed PredicateTestBase to MockPredicateTestBase to reduce confusion and added BasicPredicateTestBase.
    
    Issues: COLLECTIONS-243, COLLECTIONS-253, COLLECTIONS-293
    ------------------------------------------------------------------------
    r641231 | skestle | 2008-03-26 02:58:51 -0700 (Wed, 26 Mar 2008) | 1 line
    
    Started incorporating Edwin's patch for COLLECTIONS-253, in preparation for COLLECTIONS-290.
    ------------------------------------------------------------------------

Added:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java   (with props)
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/MockPredicateTestBase.java   (with props)
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAll.java   (with props)
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAllPredicate.java   (with props)
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java   (with props)
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java   (with props)
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java   (with props)
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestNullPredicate.java   (with props)

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java Tue Sep 15 05:57:05 2009
@@ -0,0 +1,38 @@
+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 abstract class BasicPredicateTestBase {
+    protected Object cObject;
+    protected String cString;
+    protected Integer cInteger;
+
+    @Before
+    public void initialiseTestObjects() throws Exception {
+        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));
+    }
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/BasicPredicateTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/MockPredicateTestBase.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/MockPredicateTestBase.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/MockPredicateTestBase.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/MockPredicateTestBase.java Tue Sep 15 05:57:05 2009
@@ -0,0 +1,89 @@
+package org.apache.commons.collections.functors;
+
+import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.replay;
+import org.junit.Before;
+import org.junit.After;
+import org.apache.commons.collections.Predicate;
+import org.easymock.EasyMock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Base class for tests of predicates which delegate to other predicates when evaluating an object.  This class
+ * provides methods to create and verify mock predicates to which to delegate.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 468603 $ $Date: 2006-10-27 17:52:37 -0700 (Fri, 27 Oct 2006) $
+ *
+ * @author Edwin Tellman
+ */
+public abstract class MockPredicateTestBase<T> {
+    /**
+     * Mock predicates created by a single test case which need to be verified after the test completes.
+     */
+    private List<Predicate<? super T>> mockPredicatesToVerify;
+    
+    /**
+     * The value to pass to mocks.
+     */
+    private final T testValue;
+
+    /**
+     * Creates a new <code>PredicateTestBase</code>.
+     *
+     * @param testValue the value to pass to mock predicates.
+     */
+    protected MockPredicateTestBase(final T testValue) {
+        this.testValue = testValue;
+    }
+
+    /**
+     * Creates the list of predicates to verify.
+     */
+    @Before
+    public final void createVerifyList()
+    {
+        mockPredicatesToVerify = new ArrayList<Predicate<? super T>>();
+    }
+
+    /**
+     * Verifies all the mock predicates created for the test.
+     */
+    @After
+    public final void verifyPredicates()
+    {
+        for (Predicate<? super T> predicate : mockPredicatesToVerify) {
+            verify(predicate);
+        }
+    }
+
+    /**
+     * Gets the value which will be passed to the mock predicates.
+     *
+     * @return the test value.
+     */
+    protected final T getTestValue() {
+        return testValue;
+    }
+
+    /**
+     * Creates a single mock predicate.
+     *
+     * @param returnValue the return value for the mock predicate, or null if the mock is not expected to be called.
+     *
+     * @return a single mock predicate.
+     */
+    @SuppressWarnings({"unchecked"})
+    protected final Predicate<T> createMockPredicate(final Boolean returnValue) {
+        final Predicate<T> mockPredicate = EasyMock.createMock(Predicate.class);
+        if (returnValue != null) {
+            EasyMock.expect(mockPredicate.evaluate(testValue)).andReturn(returnValue);
+        }
+        replay(mockPredicate);
+        mockPredicatesToVerify.add(mockPredicate);
+
+        return mockPredicate;
+    }
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/MockPredicateTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAll.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAll.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAll.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAll.java Tue Sep 15 05:57:05 2009
@@ -0,0 +1,21 @@
+package org.apache.commons.collections.functors;
+
+import junit.framework.TestCase;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Entry point for all Functors package tests.
+ *
+ * @version $Revision: 471163 $ $Date: 2006-11-04 02:56:39 -0800 (Sat, 04 Nov 2006) $
+ *
+ * @author Edwin Tellman
+ */
+@RunWith(Suite.class)
+@SuiteClasses({TestAllPredicate.class,
+    TestEqualPredicate.class,
+    TestNullPredicate.class})
+public class TestAll extends TestCase {
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAllPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAllPredicate.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAllPredicate.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAllPredicate.java Tue Sep 15 05:57:05 2009
@@ -0,0 +1,130 @@
+package org.apache.commons.collections.functors;
+
+import junit.framework.JUnit4TestAdapter;
+import org.apache.commons.collections.Predicate;
+
+import static org.apache.commons.collections.functors.AllPredicate.allPredicate;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * Tests the org.apache.commons.collections.functors.AllPredicate class.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 468603 $ $Date: 2006-10-27 17:52:37 -0700 (Fri, 27 Oct 2006) $
+ *
+ * @author Edwin Tellman
+ */
+public class TestAllPredicate extends TestAnyAllOnePredicate<Integer> {
+
+    /**
+     * Creates a JUnit3 test suite.
+     *
+     * @return a JUnit3 test suite
+     */
+    public static junit.framework.Test suite() {
+        return new JUnit4TestAdapter(TestAllPredicate.class);
+    }
+    
+    /**
+     * Creates a new <code>TestAllPredicate</code>.
+     */
+    public TestAllPredicate() {
+        super(42);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected final Predicate<Integer> getPredicateInstance(final Predicate<? super Integer> ... predicates) {
+        return AllPredicate.allPredicate(predicates);
+    }
+
+    /**
+     * {@inheritDoc}
+     */    
+    @Override
+    protected final Predicate<Integer> getPredicateInstance(final Collection<Predicate<Integer>> predicates) {
+        return AllPredicate.allPredicate(predicates);
+    }
+
+    /**
+     * Verifies that providing an empty predicate array evaluates to true.
+     */
+    @SuppressWarnings({"unchecked"})
+    @Test
+    public void emptyArrayToGetInstance() {
+        assertTrue("empty array not true", getPredicateInstance(new Predicate[] {}).evaluate(null));
+    }
+
+    /**
+     * Verifies that providing an empty predicate collection evaluates to true.
+     */
+    @Test
+    public void emptyCollectionToGetInstance() {
+        final Predicate<Integer> allPredicate = getPredicateInstance(
+                Collections.<Predicate<Integer>>emptyList());
+        assertTrue("empty collection not true", allPredicate.evaluate(getTestValue()));
+    }
+
+    /**
+     * Tests whether a single true predicate evaluates to true.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void oneTruePredicate() {
+        // use the constructor directly, as getInstance() returns the original predicate when passed
+        // an array of size one.
+        final Predicate<Integer> predicate = createMockPredicate(true);
+        
+        assertTrue("single true predicate evaluated to false",
+                allPredicate(predicate).evaluate(getTestValue()));
+    }
+
+    /**
+     * Tests whether a single false predicate evaluates to true.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void oneFalsePredicate() {
+        // use the constructor directly, as getInstance() returns the original predicate when passed
+        // an array of size one.
+        final Predicate<Integer> predicate = createMockPredicate(false);
+        assertFalse("single false predicate evaluated to true",
+                allPredicate(predicate).evaluate(getTestValue()));
+    }
+
+    /**
+     * Tests whether multiple true predicates evaluates to true.
+     */
+    @Test
+    public void allTrue() {
+        assertTrue("multiple true predicates evaluated to false",
+                getPredicateInstance(true, true).evaluate(getTestValue()));
+        assertTrue("multiple true predicates evaluated to false",
+                getPredicateInstance(true, true, true).evaluate(getTestValue()));
+    }
+
+    /**
+     * Tests whether combining some true and one false evalutes to false.  Also verifies that only the first
+     * false predicate is actually evaluated
+     */
+    @Test
+    public void trueAndFalseCombined() {
+        assertFalse("false predicate evaluated to true",
+                getPredicateInstance(false, null).evaluate(getTestValue()));
+        assertFalse("false predicate evaluated to true",
+                getPredicateInstance(false, null, null).evaluate(getTestValue()));
+        assertFalse("false predicate evaluated to true",
+                getPredicateInstance(true, false, null).evaluate(getTestValue()));
+        assertFalse("false predicate evaluated to true",
+                getPredicateInstance(true, true, false).evaluate(getTestValue()));
+        assertFalse("false predicate evaluated to true",
+                getPredicateInstance(true, true, false, null).evaluate(getTestValue()));
+    }
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAllPredicate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java Tue Sep 15 05:57:05 2009
@@ -0,0 +1,79 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.commons.collections.functors;
+
+import org.apache.commons.collections.Predicate;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+import java.util.Collections;
+
+/**
+ * Base class for tests of AnyPredicate, AllPredicate, and OnePredicate.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 468603 $ $Date: 2006-10-27 17:52:37 -0700 (Fri, 27 Oct 2006) $
+ *
+ * @author Edwin Tellman
+ */
+public abstract class TestAnyAllOnePredicate<T> extends TestCompositePredicate<T> {
+
+    /**
+     * Creates a new <code>TestCompositePredicate</code>.
+     *
+     * @param testValue the value which the mock predicates should expect to see (may be null).
+     */
+    protected TestAnyAllOnePredicate(final T testValue) {
+        super(testValue);
+    }
+
+    /**
+     * Tests whether <code>getInstance</code> with a one element array returns the first element in the array.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public final void singleElementArrayToGetInstance() {
+        final Predicate<T> predicate = createMockPredicate(null);
+        final Predicate<T> allPredicate = getPredicateInstance(predicate);
+        assertSame("expected argument to be returned by getInstance()", predicate, allPredicate);
+    }
+
+    /**
+     * Tests that passing a singleton collection to <code>getInstance</code> returns the single element in the
+     * collection.
+     */
+    @Test
+    public final void singletonCollectionToGetInstance() {
+        final Predicate<T> predicate = createMockPredicate(null);
+        final Predicate<T> allPredicate = getPredicateInstance(
+                Collections.<Predicate<T>>singleton(predicate));
+        assertSame("expected singleton collection member to be returned by getInstance()",
+                predicate, allPredicate);
+    }
+
+    /**
+     * Tests creating composite predicate instances with single predicates and verifies that the composite returns
+     * the same value as the single predicate does. 
+     */
+    public final void singleValues() {
+        assertTrue(getPredicateInstance(true).evaluate(null));
+        assertFalse(getPredicateInstance(false).evaluate(null));
+    }
+
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java Tue Sep 15 05:57:05 2009
@@ -0,0 +1,132 @@
+package org.apache.commons.collections.functors;
+
+import org.apache.commons.collections.Predicate;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * Base class for tests of composite predicates.
+ *
+ * @since Commons Collections 3.0
+ * @version $Revision: 468603 $ $Date: 2006-10-27 17:52:37 -0700 (Fri, 27 Oct 2006) $
+ *
+ * @author Edwin Tellman
+ */
+public abstract class TestCompositePredicate<T> extends MockPredicateTestBase<T> {
+
+    /**
+     * Creates a new <code>TestCompositePredicate</code>.
+     *
+     * @param testValue the value which the mock predicates should expect to see (may be null).
+     */
+    protected TestCompositePredicate(final T testValue) {
+        super(testValue);
+    }
+
+    /**
+     * Creates an instance of the predicate to test.
+     *
+     * @param predicates the arguments to <code>getInstance</code>.
+     *
+     * @return a predicate to test.
+     */
+    protected abstract Predicate<T> getPredicateInstance(final Predicate<? super T> ... predicates);
+
+    /**
+     * Creates an instance of the predicate to test.
+     *
+     * @param predicates the argument to <code>getInstance</code>.
+     *
+     * @return a predicate to test.
+     */
+    protected abstract Predicate<T> getPredicateInstance(final Collection<Predicate<T>> predicates);
+
+    /**
+     * Creates an instance of the predicate to test.
+     *
+     * @param mockReturnValues the return values for the mock predicates, or null if that mock is not expected
+     *                         to be called
+     *
+     * @return a predicate to test.
+     */
+    protected final Predicate<T> getPredicateInstance(final Boolean... mockReturnValues) {
+        final List<Predicate<T>> predicates = new ArrayList<Predicate<T>>();
+        for (Boolean returnValue : mockReturnValues) {
+            predicates.add(createMockPredicate(returnValue));
+        }
+        return getPredicateInstance(predicates);
+    }
+
+    /**
+     * Tests whether <code>getInstance</code> with a one element array returns the first element in the array.
+     */
+    @SuppressWarnings("unchecked")
+    public void singleElementArrayToGetInstance() {
+        final Predicate<T> predicate = createMockPredicate(null);
+        final Predicate<T> allPredicate = getPredicateInstance(predicate);
+        Assert.assertSame("expected argument to be returned by getInstance()", predicate, allPredicate);
+    }
+
+    /**
+     * Tests that passing a singleton collection to <code>getInstance</code> returns the single element in the
+     * collection.
+     */
+    public void singletonCollectionToGetInstance() {
+        final Predicate<T> predicate = createMockPredicate(null);
+        final Predicate<T> allPredicate = getPredicateInstance(
+                Collections.<Predicate<T>>singleton(predicate));
+        Assert.assertSame("expected argument to be returned by getInstance()", predicate, allPredicate);
+    }
+
+    /**
+     * Tests <code>getInstance</code> with a null predicate array.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public final void nullArrayToGetInstance() {
+        getPredicateInstance((Predicate<T>[]) null);
+    }
+
+    /**
+     * Tests <code>getInstance</code> with a single null element in the predicate array.
+     */
+    @SuppressWarnings({"unchecked"})
+    @Test(expected = IllegalArgumentException.class)
+    public final void nullElementInArrayToGetInstance() {
+        getPredicateInstance(new Predicate[] { null });
+    }
+
+    /**
+     * Tests <code>getInstance</code> with two null elements in the predicate array.
+     */
+    @SuppressWarnings({"unchecked"})
+    @Test(expected = IllegalArgumentException.class)
+    public final void nullElementsInArrayToGetInstance() {
+        getPredicateInstance(new Predicate[] { null, null });
+    }
+
+
+    /**
+     * Tests <code>getInstance</code> with a null predicate collection
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public final void nullCollectionToGetInstance() {
+        getPredicateInstance((Collection<Predicate<T>>) null);
+    }
+
+    /**
+     * Tests <code>getInstance</code> with a predicate collection that contains null elements
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public final void nullElementsInCollectionToGetInstance() {
+        final Collection<Predicate<T>> coll = new ArrayList<Predicate<T>>();
+        coll.add(null);
+        coll.add(null);
+        getPredicateInstance(coll);
+    }
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java Tue Sep 15 05:57:05 2009
@@ -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<Object> 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((Number) 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;
+        }
+    }
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestEqualPredicate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestNullPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestNullPredicate.java?rev=815113&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestNullPredicate.java (added)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestNullPredicate.java Tue Sep 15 05:57:05 2009
@@ -0,0 +1,26 @@
+package org.apache.commons.collections.functors;
+
+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 TestNullPredicate extends BasicPredicateTestBase {
+    @Test
+    public void testNullPredicate() {
+        assertSame(NullPredicate.nullPredicate(), NullPredicate.nullPredicate());
+        assertTrue(nullPredicate(), null);
+    }
+    
+    public void ensurePredicateCanBeTypedWithoutWarning() throws Exception {
+        Predicate<String> predicate = NullPredicate.nullPredicate();
+        assertFalse(predicate, cString);
+    }
+
+    @Override
+    protected Predicate<?> generatePredicate() {
+        return nullPredicate();
+    }    
+}

Propchange: commons/proper/collections/trunk/src/test/org/apache/commons/collections/functors/TestNullPredicate.java
------------------------------------------------------------------------------
    svn:eol-style = native