diff --git a/src/java/org/apache/commons/collections/PredicateUtils.java b/src/java/org/apache/commons/collections/PredicateUtils.java index 19d519e5e..da149e01b 100644 --- a/src/java/org/apache/commons/collections/PredicateUtils.java +++ b/src/java/org/apache/commons/collections/PredicateUtils.java @@ -16,6 +16,9 @@ */ package org.apache.commons.collections; +import static org.apache.commons.collections.functors.AllPredicate.allPredicate; +import static org.apache.commons.collections.functors.TruePredicate.truePredicate; + import java.util.Collection; import org.apache.commons.collections.functors.AllPredicate; @@ -103,8 +106,8 @@ public class PredicateUtils { * * @return the predicate */ - public static Predicate truePredicate() { - return TruePredicate.INSTANCE; + public static Predicate truePredicate() { + return truePredicate(); } /** @@ -274,8 +277,8 @@ public class PredicateUtils { * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static Predicate allPredicate(Predicate[] predicates) { - return AllPredicate.getInstance(predicates); + public static Predicate allPredicate(Predicate[] predicates) { + return allPredicate(predicates); } /** @@ -290,8 +293,8 @@ public class PredicateUtils { * @throws IllegalArgumentException if the predicates collection is null * @throws IllegalArgumentException if any predicate in the collection is null */ - public static Predicate allPredicate(Collection predicates) { - return AllPredicate.getInstance(predicates); + public static Predicate allPredicate(Collection> predicates) { + return allPredicate(predicates); } /** diff --git a/src/java/org/apache/commons/collections/functors/AllPredicate.java b/src/java/org/apache/commons/collections/functors/AllPredicate.java index ef3821b8f..cce6f8e07 100644 --- a/src/java/org/apache/commons/collections/functors/AllPredicate.java +++ b/src/java/org/apache/commons/collections/functors/AllPredicate.java @@ -16,6 +16,10 @@ */ package org.apache.commons.collections.functors; +import static org.apache.commons.collections.functors.FunctorUtils.coerce; +import static org.apache.commons.collections.functors.FunctorUtils.validate; +import static org.apache.commons.collections.functors.TruePredicate.truePredicate; + import java.io.Serializable; import java.util.Collection; @@ -34,14 +38,15 @@ import org.apache.commons.collections.Predicate; * * @author Stephen Colebourne * @author Matt Benson + * @author Stephen Kestle */ -public final class AllPredicate implements Predicate, PredicateDecorator, Serializable { +public final class AllPredicate implements Predicate, PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -3094696765038308799L; /** The array of predicates to call */ - private final Predicate[] iPredicates; + private final Predicate[] iPredicates; /** * Factory to create the predicate. @@ -53,17 +58,49 @@ public final class AllPredicate implements Predicate, PredicateDecorator, Serial * @return the all predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null + * @deprecated Use {@link #allPredicate(Predicate...)} instead */ - public static Predicate getInstance(Predicate[] predicates) { + public static Predicate getInstance(Predicate ... predicates) { + return allPredicate(predicates); + } + + /** + * Factory to create the predicate. + *

+ * If the array is size zero, the predicate always returns true. + * If the array is size one, then that predicate is returned. + * + * @param predicates the predicates to check, cloned, not null + * @return the all predicate + * @throws IllegalArgumentException if the predicates array is null + * @throws IllegalArgumentException if any predicate in the array is null + */ + public static Predicate allPredicate(Predicate ... predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { - return TruePredicate.INSTANCE; + return truePredicate(); } if (predicates.length == 1) { - return predicates[0]; + return coerce(predicates[0]); } - predicates = FunctorUtils.copy(predicates); - return new AllPredicate(predicates); + + return new AllPredicate(FunctorUtils.copy(predicates)); + } + + /** + * Factory to create the predicate. + *

+ * If the collection is size zero, the predicate always returns true. + * If the collection is size one, then that predicate is returned. + * + * @param predicates the predicates to check, cloned, not null + * @return the all predicate + * @throws IllegalArgumentException if the predicates array is null + * @throws IllegalArgumentException if any predicate in the array is null + * @deprecated Use {@link #allPredicate(Collection>)} instead + */ + public static Predicate getInstance(Collection> predicates) { + return allPredicate(predicates); } /** @@ -77,24 +114,24 @@ public final class AllPredicate implements Predicate, PredicateDecorator, Serial * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static Predicate getInstance(Collection predicates) { - Predicate[] preds = FunctorUtils.validate(predicates); + public static Predicate allPredicate(Collection> predicates) { + final Predicate[] preds = validate(predicates); if (preds.length == 0) { - return TruePredicate.INSTANCE; + return truePredicate(); } if (preds.length == 1) { - return preds[0]; + return coerce(preds[0]); } - return new AllPredicate(preds); + return new AllPredicate(preds); } /** * Constructor that performs no validation. * Use getInstance if you want that. - * + * * @param predicates the predicates to check, not cloned, not null */ - public AllPredicate(Predicate[] predicates) { + public AllPredicate(Predicate ... predicates) { super(); iPredicates = predicates; } @@ -105,9 +142,9 @@ public final class AllPredicate implements Predicate, PredicateDecorator, Serial * @param object the input object * @return true if all decorated predicates return true */ - public boolean evaluate(Object object) { - for (int i = 0; i < iPredicates.length; i++) { - if (iPredicates[i].evaluate(object) == false) { + public boolean evaluate(T object) { + for (Predicate iPredicate : iPredicates) { + if (!iPredicate.evaluate(object)) { return false; } } @@ -120,7 +157,7 @@ public final class AllPredicate implements Predicate, PredicateDecorator, Serial * @return the predicates * @since Commons Collections 3.1 */ - public Predicate[] getPredicates() { + public Predicate[] getPredicates() { return iPredicates; } diff --git a/src/java/org/apache/commons/collections/functors/FunctorUtils.java b/src/java/org/apache/commons/collections/functors/FunctorUtils.java index 3bff47182..d52ba0180 100644 --- a/src/java/org/apache/commons/collections/functors/FunctorUtils.java +++ b/src/java/org/apache/commons/collections/functors/FunctorUtils.java @@ -17,7 +17,6 @@ package org.apache.commons.collections.functors; import java.util.Collection; -import java.util.Iterator; import org.apache.commons.collections.Closure; import org.apache.commons.collections.Predicate; @@ -43,15 +42,35 @@ class FunctorUtils { /** * Clone the predicates to ensure that the internal reference can't be messed with. + * Due to the {@link Predicate#evaluate(T)} method, Predicate is + * able to be coerced to Predicate without casting issues. * * @param predicates the predicates to copy * @return the cloned predicates */ - static Predicate[] copy(Predicate[] predicates) { + @SuppressWarnings("unchecked") + static Predicate[] copy(Predicate[] predicates) { if (predicates == null) { return null; } - return (Predicate[]) predicates.clone(); + return predicates.clone(); + } + + /** + * A very simple method that coerces Predicate to Predicate. + * Due to the {@link Predicate#evaluate(T)} method, Predicate is + * able to be coerced to Predicate without casting issues. + *

This method exists + * simply as centralised documentation and atomic unchecked warning + * suppression. + * + * @param the type of object the returned predicate should "accept" + * @param predicate the predicate to coerce. + * @return the coerced predicate. + */ + @SuppressWarnings("unchecked") + static Predicate coerce(Predicate predicate){ + return (Predicate) predicate; } /** @@ -59,7 +78,7 @@ class FunctorUtils { * * @param predicates the predicates to validate */ - static void validate(Predicate[] predicates) { + static void validate(Predicate[] predicates) { if (predicates == null) { throw new IllegalArgumentException("The predicate array must not be null"); } @@ -76,15 +95,16 @@ class FunctorUtils { * @param predicates the predicates to validate * @return predicate array */ - static Predicate[] validate(Collection predicates) { + @SuppressWarnings("unchecked") + static Predicate[] validate(Collection> predicates) { if (predicates == null) { throw new IllegalArgumentException("The predicate collection must not be null"); } // convert to array like this to guarantee iterator() ordering - Predicate[] preds = new Predicate[predicates.size()]; + Predicate[] preds = new Predicate[predicates.size()]; int i = 0; - for (Iterator it = predicates.iterator(); it.hasNext();) { - preds[i] = (Predicate) it.next(); + for (Predicate predicate : predicates) { + preds[i] = predicate; if (preds[i] == null) { throw new IllegalArgumentException("The predicate collection must not contain a null predicate, index " + i + " was null"); } diff --git a/src/java/org/apache/commons/collections/functors/PredicateDecorator.java b/src/java/org/apache/commons/collections/functors/PredicateDecorator.java index b7e8e9e73..9e61b9258 100644 --- a/src/java/org/apache/commons/collections/functors/PredicateDecorator.java +++ b/src/java/org/apache/commons/collections/functors/PredicateDecorator.java @@ -27,8 +27,9 @@ import org.apache.commons.collections.Predicate; * @version $Revision$ $Date$ * * @author Stephen Colebourne + * @author Stephen Kestle */ -public interface PredicateDecorator extends Predicate { +public interface PredicateDecorator extends Predicate { /** * Gets the predicates being decorated as an array. @@ -38,6 +39,6 @@ public interface PredicateDecorator extends Predicate { * * @return the predicates being decorated */ - Predicate[] getPredicates(); + Predicate[] getPredicates(); } diff --git a/src/java/org/apache/commons/collections/functors/TruePredicate.java b/src/java/org/apache/commons/collections/functors/TruePredicate.java index 1ce1a07bb..3cdf80df2 100644 --- a/src/java/org/apache/commons/collections/functors/TruePredicate.java +++ b/src/java/org/apache/commons/collections/functors/TruePredicate.java @@ -27,14 +27,27 @@ import org.apache.commons.collections.Predicate; * @version $Revision$ $Date$ * * @author Stephen Colebourne + * @author Stephen Kestle */ -public final class TruePredicate implements Predicate, Serializable { +public final class TruePredicate implements Predicate, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3374767158756189740L; /** Singleton predicate instance */ - public static final Predicate INSTANCE = new TruePredicate(); + public static final Predicate INSTANCE = new TruePredicate(); + + /** + * Factory returning the singleton instance. + * + * @return the singleton instance + * @since Commons Collections 3.1 + * @deprecated + */ + @Deprecated + public static Predicate getInstance() { + return truePredicate(); + } /** * Factory returning the singleton instance. @@ -42,8 +55,9 @@ public final class TruePredicate implements Predicate, Serializable { * @return the singleton instance * @since Commons Collections 3.1 */ - public static Predicate getInstance() { - return INSTANCE; + @SuppressWarnings("unchecked") + public static Predicate truePredicate() { + return (Predicate) INSTANCE; } /** @@ -59,8 +73,7 @@ public final class TruePredicate implements Predicate, Serializable { * @param object the input object * @return true always */ - public boolean evaluate(Object object) { + public boolean evaluate(T object) { return true; } - } diff --git a/src/test/org/apache/commons/collections/functors/PredicateTestBase.java b/src/test/org/apache/commons/collections/functors/PredicateTestBase.java new file mode 100644 index 000000000..87f35ba04 --- /dev/null +++ b/src/test/org/apache/commons/collections/functors/PredicateTestBase.java @@ -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 PredicateTestBase { + /** + * Mock predicates created by a single test case which need to be verified after the test completes. + */ + private List> mockPredicatesToVerify; + + /** + * The value to pass to mocks. + */ + private final T testValue; + + /** + * Creates a new PredicateTestBase. + * + * @param testValue the value to pass to mock predicates. + */ + protected PredicateTestBase(final T testValue) { + this.testValue = testValue; + } + + /** + * Creates the list of predicates to verify. + */ + @Before + public final void createVerifyList() + { + mockPredicatesToVerify = new ArrayList>(); + } + + /** + * Verifies all the mock predicates created for the test. + */ + @After + public final void verifyPredicates() + { + for (Predicate 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 createMockPredicate(final Boolean returnValue) { + final Predicate mockPredicate = EasyMock.createMock(Predicate.class); + if (returnValue != null) { + EasyMock.expect(mockPredicate.evaluate(testValue)).andReturn(returnValue); + } + replay(mockPredicate); + mockPredicatesToVerify.add(mockPredicate); + + return mockPredicate; + } +} diff --git a/src/test/org/apache/commons/collections/functors/TestAll.java b/src/test/org/apache/commons/collections/functors/TestAll.java new file mode 100644 index 000000000..8284fc465 --- /dev/null +++ b/src/test/org/apache/commons/collections/functors/TestAll.java @@ -0,0 +1,19 @@ +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}) +public class TestAll extends TestCase { +} diff --git a/src/test/org/apache/commons/collections/functors/TestAllPredicate.java b/src/test/org/apache/commons/collections/functors/TestAllPredicate.java new file mode 100644 index 000000000..db52bca59 --- /dev/null +++ b/src/test/org/apache/commons/collections/functors/TestAllPredicate.java @@ -0,0 +1,134 @@ +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 { + + /** + * Creates a JUnit3 test suite. + * + * @return a JUnit3 test suite + */ + public static junit.framework.Test suite() { + return new JUnit4TestAdapter(TestAllPredicate.class); + } + + /** + * Creates a new TestAllPredicate. + */ + public TestAllPredicate() { + super(42); + } + + /** + * {@inheritDoc} + */ + @Override + protected final Predicate getPredicateInstance(final Predicate ... predicates) { + return AllPredicate.allPredicate(predicates); + } + + /** + * {@inheritDoc} + */ + @Override + protected final Predicate getPredicateInstance(final Collection> 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 allPredicate = getPredicateInstance( + Collections.>emptyList()); + assertTrue("empty collection not true", allPredicate.evaluate(getTestValue())); + } + + /** + * Tests whether a single true predicate evaluates to true. + */ + @Test + public void oneTruePredicate() + { + // use the constructor directly, as getInstance() returns the original predicate when passed + // an array of size one. + final Predicate predicate = createMockPredicate(true); + + assertTrue("single true predicate evaluated to false", + allPredicate(predicate).evaluate(getTestValue())); + } + + /** + * Tests whether a single false predicate evaluates to true. + */ + @Test + public void oneFalsePredicate() + { + // use the constructor directly, as getInstance() returns the original predicate when passed + // an array of size one. + final Predicate 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())); + } +} diff --git a/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java b/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java new file mode 100644 index 000000000..c55cdf012 --- /dev/null +++ b/src/test/org/apache/commons/collections/functors/TestAnyAllOnePredicate.java @@ -0,0 +1,66 @@ +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 extends TestCompositePredicate { + + /** + * Creates a new TestCompositePredicate. + * + * @param testValue the value which the mock predicates should expect to see (may be null). + */ + protected TestAnyAllOnePredicate(final T testValue) { + super(testValue); + } + + + /** + * Tests whether getInstance with a one element array returns the first element in the array. + */ + @Test + public final void singleElementArrayToGetInstance() + { + final Predicate predicate = createMockPredicate(null); + final Predicate allPredicate = getPredicateInstance(predicate); + assertSame("expected argument to be returned by getInstance()", predicate, allPredicate); + } + + /** + * Tests that passing a singleton collection to getInstance returns the single element in the + * collection. + */ + @Test + public final void singletonCollectionToGetInstance() + { + final Predicate predicate = createMockPredicate(null); + final Predicate allPredicate = getPredicateInstance( + Collections.>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)); + } + +} diff --git a/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java b/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java new file mode 100644 index 000000000..88b4703fe --- /dev/null +++ b/src/test/org/apache/commons/collections/functors/TestCompositePredicate.java @@ -0,0 +1,135 @@ +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 extends PredicateTestBase { + + /** + * Creates a new TestCompositePredicate. + * + * @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 getInstance. + * + * @return a predicate to test. + */ + protected abstract Predicate getPredicateInstance(final Predicate ... predicates); + + /** + * Creates an instance of the predicate to test. + * + * @param predicates the argument to getInstance. + * + * @return a predicate to test. + */ + protected abstract Predicate getPredicateInstance(final Collection> 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 getPredicateInstance(final Boolean ... mockReturnValues) + { + final List> predicates = new ArrayList>(); + for (Boolean returnValue : mockReturnValues) { + predicates.add(createMockPredicate(returnValue)); + } + return getPredicateInstance(predicates); + } + + /** + * Tests whether getInstance with a one element array returns the first element in the array. + */ + public void singleElementArrayToGetInstance() + { + final Predicate predicate = createMockPredicate(null); + final Predicate allPredicate = getPredicateInstance(predicate); + Assert.assertSame("expected argument to be returned by getInstance()", predicate, allPredicate); + } + + /** + * Tests that passing a singleton collection to getInstance returns the single element in the + * collection. + */ + public void singletonCollectionToGetInstance() + { + final Predicate predicate = createMockPredicate(null); + final Predicate allPredicate = getPredicateInstance( + Collections.>singleton(predicate)); + Assert.assertSame("expected argument to be returned by getInstance()", predicate, allPredicate); + } + + /** + * Tests getInstance with a null predicate array. + */ + @SuppressWarnings({"unchecked"}) + @Test(expected = IllegalArgumentException.class) + public final void nullArrayToGetInstance() { + getPredicateInstance((Predicate[]) null); + } + + /** + * Tests getInstance with a single null element in the predicate array. + */ + @SuppressWarnings({"unchecked"}) + @Test(expected = IllegalArgumentException.class) + public final void nullElementInArrayToGetInstance() { + getPredicateInstance(new Predicate[] { null }); + } + + /** + * Tests getInstance with two null elements in the predicate array. + */ + @SuppressWarnings({"unchecked"}) + @Test(expected = IllegalArgumentException.class) + public final void nullElementsInArrayToGetInstance() { + getPredicateInstance(new Predicate[] { null, null }); + } + + + /** + * Tests getInstance with a null predicate collection + */ + @Test(expected = IllegalArgumentException.class) + public final void nullCollectionToGetInstance() { + getPredicateInstance((Collection>) null); + } + + /** + * Tests getInstance with a predicate collection that contains null elements + */ + @Test(expected = IllegalArgumentException.class) + public final void nullElementsInCollectionToGetInstance() { + final Collection> coll = new ArrayList>(); + coll.add(null); + coll.add(null); + getPredicateInstance(coll); + } +} diff --git a/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java b/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java index e830ffa49..1665a2dc4 100644 --- a/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java +++ b/src/test/org/apache/commons/collections/iterators/TestFilterIterator.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections.iterators; +import static org.apache.commons.collections.functors.TruePredicate.truePredicate; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -125,7 +127,7 @@ public class TestFilterIterator extends AbstractTestIterator { Iterator iter2 = Collections.EMPTY_LIST.iterator(); FilterIterator filterIterator = new FilterIterator(iter1); - filterIterator.setPredicate(TruePredicate.getInstance()); + filterIterator.setPredicate(truePredicate()); // this iterator has elements assertEquals(true, filterIterator.hasNext()); @@ -142,7 +144,7 @@ public class TestFilterIterator extends AbstractTestIterator { Iterator iter = Collections.singleton(null).iterator(); FilterIterator filterIterator = new FilterIterator(iter); - filterIterator.setPredicate(TruePredicate.getInstance()); + filterIterator.setPredicate(truePredicate()); // this predicate matches assertEquals(true, filterIterator.hasNext());