Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 13686 invoked from network); 19 Sep 2003 22:22:00 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 19 Sep 2003 22:22:00 -0000 Received: (qmail 23803 invoked by uid 500); 19 Sep 2003 22:21:43 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 23467 invoked by uid 500); 19 Sep 2003 22:21:41 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 23454 invoked by uid 500); 19 Sep 2003 22:21:41 -0000 Received: (qmail 23451 invoked from network); 19 Sep 2003 22:21:40 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 19 Sep 2003 22:21:40 -0000 Received: (qmail 13624 invoked by uid 1718); 19 Sep 2003 22:21:54 -0000 Date: 19 Sep 2003 22:21:54 -0000 Message-ID: <20030919222154.13623.qmail@minotaur.apache.org> From: psteitz@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/decorators TestPredicatedBag.java TestPredicatedSortedBag.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N psteitz 2003/09/19 15:21:53 Modified: collections/src/test/org/apache/commons/collections/decorators TestPredicatedBag.java TestPredicatedSortedBag.java Log: Modified TestPredicatedBag, TestPredicatedSortedBag to use identically true predicate in makeBag override. Previous versions depended on the fact that TestBag only adds Strings. Revision Changes Path 1.2 +19 -8 jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedBag.java Index: TestPredicatedBag.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedBag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestPredicatedBag.java 9 Sep 2003 03:03:57 -0000 1.1 +++ TestPredicatedBag.java 19 Sep 2003 22:21:53 -0000 1.2 @@ -65,6 +65,7 @@ import org.apache.commons.collections.HashBag; import org.apache.commons.collections.TestBag; import org.apache.commons.collections.Predicate; +import org.apache.commons.collections.PredicateUtils; /** * Extension of {@link TestBag} for exercising the {@link PredicatedBag} @@ -89,25 +90,35 @@ String[] testCaseName = { TestPredicatedBag.class.getName()}; junit.textui.TestRunner.main(testCaseName); } + + //-------------------------------------------------------------------------- - protected Predicate getPredicate() { + protected Predicate stringPredicate() { return new Predicate() { public boolean evaluate(Object o) { return o instanceof String; } }; - } + } + + protected Predicate truePredicate = PredicateUtils.truePredicate(); protected Bag decorateBag(HashBag bag, Predicate predicate) { return PredicatedBag.decorate(bag, predicate); } public Bag makeBag() { - return decorateBag(new HashBag(), getPredicate()); + return decorateBag(new HashBag(), truePredicate); } + + public Bag makeTestBag() { + return decorateBag(new HashBag(), stringPredicate()); + } + + //-------------------------------------------------------------------------- public void testlegalAddRemove() { - Bag bag = makeBag(); + Bag bag = makeTestBag(); assertEquals(0, bag.size()); Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "1"}; for (int i = 0; i < els.length; i++) { @@ -124,7 +135,7 @@ } public void testIllegalAdd() { - Bag bag = makeBag(); + Bag bag = makeTestBag(); Integer i = new Integer(3); try { bag.add(i); @@ -143,7 +154,7 @@ elements.add(new Integer(3)); elements.add("four"); try { - Bag bag = decorateBag(elements, getPredicate()); + Bag bag = decorateBag(elements, stringPredicate()); fail("Bag contains an element that should fail the predicate."); } catch (IllegalArgumentException e) { // expected 1.2 +27 -17 jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedSortedBag.java Index: TestPredicatedSortedBag.java =================================================================== RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedSortedBag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestPredicatedSortedBag.java 9 Sep 2003 03:03:57 -0000 1.1 +++ TestPredicatedSortedBag.java 19 Sep 2003 22:21:53 -0000 1.2 @@ -66,6 +66,7 @@ import org.apache.commons.collections.TreeBag; import org.apache.commons.collections.Predicate; import org.apache.commons.collections.TestBag; +import org.apache.commons.collections.PredicateUtils; /** * Extension of {@link TestBag} for exercising the {@link PredicatedSortedBag} @@ -85,47 +86,56 @@ super(testName); } - protected Predicate getPredicate() { + public static Test suite() { + return new TestSuite(TestPredicatedSortedBag.class); + } + + public static void main(String args[]) { + String[] testCaseName = { TestPredicatedSortedBag.class.getName()}; + junit.textui.TestRunner.main(testCaseName); + } + + //-------------------------------------------------------------------------- + + protected Predicate stringPredicate() { return new Predicate() { public boolean evaluate(Object o) { return o instanceof String; } }; - } + } + + protected Predicate truePredicate = PredicateUtils.truePredicate(); protected SortedBag decorateBag(SortedBag bag, Predicate predicate) { return PredicatedSortedBag.decorate(bag, predicate); } public Bag makeBag() { - return decorateBag(emptyBag, getPredicate()); - } - - public static Test suite() { - return new TestSuite(TestPredicatedSortedBag.class); + return decorateBag(emptyBag, truePredicate); } - - public static void main(String args[]) { - String[] testCaseName = { TestPredicatedSortedBag.class.getName()}; - junit.textui.TestRunner.main(testCaseName); + + public Bag makeTestBag() { + return decorateBag(emptyBag, stringPredicate()); } + //-------------------------------------------------------------------------- + public void testDecorate() { - SortedBag bag = decorateBag(emptyBag, getPredicate()); + SortedBag bag = decorateBag(emptyBag, stringPredicate()); SortedBag bag2 = ((PredicatedSortedBag) bag).getSortedBag(); try { SortedBag bag3 = decorateBag(emptyBag, null); fail("Expecting IllegalArgumentException for null predicate"); } catch (IllegalArgumentException e) {} try { - SortedBag bag4 = decorateBag(nullBag, getPredicate()); + SortedBag bag4 = decorateBag(nullBag, stringPredicate()); fail("Expecting IllegalArgumentException for null bag"); } catch (IllegalArgumentException e) {} } public void testSortOrder() { - PredicatedSortedBag bag = - (PredicatedSortedBag) decorateBag(emptyBag, getPredicate()); + SortedBag bag = decorateBag(emptyBag, stringPredicate()); String one = "one"; String two = "two"; String three = "three"; --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org