You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2003/09/20 00:21:54 UTC

cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/decorators TestPredicatedBag.java TestPredicatedSortedBag.java

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