commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/decorators TestPredicatedBuffer.java TestPredicatedCollection.java TestPredicatedList.java TestPredicatedSet.java TestAll.java
Date Fri, 12 Sep 2003 03:59:00 GMT
psteitz     2003/09/11 20:59:00

  Modified:    collections/src/test/org/apache/commons/collections
                        TestBufferUtils.java TestCollectionUtils.java
                        TestListUtils.java TestSetUtils.java
               collections/src/test/org/apache/commons/collections/decorators
                        TestAll.java
  Added:       collections/src/test/org/apache/commons/collections/decorators
                        TestPredicatedBuffer.java
                        TestPredicatedCollection.java
                        TestPredicatedList.java TestPredicatedSet.java
  Removed:     collections/src/test/org/apache/commons/collections
                        TestPredicatedCollection.java
  Log:
  Moved TestPredicatedCollection to decorators test package.
  Added TestPredicatedBuffer, TestPredicatedList, TestPredicatedSet.
  Modified TestBufferUtils, TestCollectionUtils, TestListUtils and TestSetUtils to eliminate
BlkTests based on TestPredicatedCollection with simple factory tests, delegating (full coverage)
functional testing to the decorator tests.
  
  Revision  Changes    Path
  1.5       +23 -36    jakarta-commons/collections/src/test/org/apache/commons/collections/TestBufferUtils.java
  
  Index: TestBufferUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBufferUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestBufferUtils.java	31 Aug 2003 17:28:43 -0000	1.4
  +++ TestBufferUtils.java	12 Sep 2003 03:59:00 -0000	1.5
  @@ -62,6 +62,7 @@
   
   import java.util.Arrays;
   import java.util.Collection;
  +import org.apache.commons.collections.decorators.PredicatedBuffer;
   
   import junit.framework.Test;
   
  @@ -83,41 +84,27 @@
       public void testNothing() {
       }
   
  -    public BulkTest bulkTestPredicatedBuffer() {
  -        return new TestPredicatedCollection("") {
  -
  -            public Collection predicatedCollection() {
  -                Predicate p = getPredicate();
  -                return BufferUtils.predicatedBuffer(new ArrayStack(), p);
  -            }
  -
  -            public BulkTest bulkTestAll() {
  -                return new TestCollection("") {
  -                    public Collection makeCollection() {
  -                        return predicatedCollection();
  -                    }
  -
  -                    public Collection makeConfirmedCollection() {
  -                        return new ArrayStack();
  -                    }
  -
  -                    public Collection makeConfirmedFullCollection() {
  -                        ArrayStack list = new ArrayStack();
  -                        list.addAll(java.util.Arrays.asList(getFullElements()));
  -                        return list;
  -                    }
  -
  -                    public Object[] getFullElements() {
  -                        return getFullNonNullStringElements();
  -                    }
  -
  -                    public Object[] getOtherElements() {
  -                        return getOtherNonNullStringElements();
  -                    }
  -
  -                };
  +    public void testpredicatedBuffer() {
  +        Predicate predicate = new Predicate() {
  +            public boolean evaluate(Object o) {
  +                return o instanceof String;
               }
           };
  +        Buffer buffer = BufferUtils.predicatedBuffer(new ArrayStack(), predicate);
  +        assertTrue("returned object should be a PredicatedBuffer",
  +            buffer instanceof PredicatedBuffer);
  +        try {
  +            buffer = BufferUtils.predicatedBuffer(new ArrayStack(), null);
  +            fail("Expecting IllegalArgumentException for null predicate.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
  +        try {
  +            buffer = BufferUtils.predicatedBuffer(null, predicate);
  +            fail("Expecting IllegalArgumentException for null buffer.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
       }
   
   
  
  
  
  1.19      +30 -37    jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java
  
  Index: TestCollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TestCollectionUtils.java	5 Sep 2003 02:16:33 -0000	1.18
  +++ TestCollectionUtils.java	12 Sep 2003 03:59:00 -0000	1.19
  @@ -74,6 +74,8 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  +import org.apache.commons.collections.decorators.PredicatedCollection;
  +
   /**
    * Tests for CollectionUtils.
    * 
  @@ -582,42 +584,33 @@
           assertEquals(new Integer(4), set.iterator().next());
       }
   
  -
  -    public BulkTest bulkTestPredicatedCollection1() {
  -        return new TestPredicatedCollection("") {
  -            public Collection predicatedCollection() {
  -                Predicate p = getPredicate();
  -                return CollectionUtils.predicatedCollection(new ArrayList(), p);
  -            }
  -
  -            public BulkTest bulkTestAll() {
  -                return new TestCollection("") {
  -                    public Collection makeCollection() {
  -                        return predicatedCollection();
  -                    }
  -
  -                    public Collection makeConfirmedCollection() {
  -                        return new ArrayList();
  -                    }
  -
  -                    public Collection makeConfirmedFullCollection() {
  -                        ArrayList list = new ArrayList();
  -                        list.addAll(java.util.Arrays.asList(getFullElements()));
  -                        return list;
  -                    }
  -
  -                    public Object[] getFullElements() {
  -                        return getFullNonNullStringElements();
  -                    }
  -
  -                    public Object[] getOtherElements() {
  -                        return getOtherNonNullStringElements();
  -                    }
  -
  -                };
  +    public void testPredicatedCollection() {
  +        Predicate predicate = new Predicate() {
  +            public boolean evaluate(Object o) {
  +                return o instanceof String;
               }
           };
  +        Collection collection = 
  +            CollectionUtils.predicatedCollection(new ArrayList(), predicate);
  +        assertTrue("returned object should be a PredicatedCollection",
  +            collection instanceof PredicatedCollection);
  +        try { 
  +           collection = 
  +                CollectionUtils.predicatedCollection(new ArrayList(), null); 
  +           fail("Expecting IllegalArgumentException for null predicate.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
  +        try { 
  +           collection = 
  +                CollectionUtils.predicatedCollection(null, predicate); 
  +           fail("Expecting IllegalArgumentException for null collection.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }             
       }
  +        
  +   
   
       public BulkTest bulkTestTypedCollection() {
           return new TestTypedCollection("") {
  
  
  
  1.11      +28 -27    jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java
  
  Index: TestListUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestListUtils.java	31 Aug 2003 17:28:43 -0000	1.10
  +++ TestListUtils.java	12 Sep 2003 03:59:00 -0000	1.11
  @@ -65,6 +65,8 @@
   import java.util.Collection;
   import java.util.List;
   
  +import org.apache.commons.collections.decorators.PredicatedList;
  +
   import junit.framework.Test;
   
   /**
  @@ -86,32 +88,31 @@
   
       public void testNothing() {
       }
  -
  -    public BulkTest bulkTestPredicatedList() {
  -        return new TestPredicatedCollection("") {
  -
  -            public Collection predicatedCollection() {
  -                Predicate p = getPredicate();
  -                return ListUtils.predicatedList(new ArrayList(), p);
  -            }
  -
  -            public BulkTest bulkTestAll() {
  -                return new TestList("") {
  -                    public List makeEmptyList() {
  -                        return (List)predicatedCollection();
  -                    }
  -
  -                    public Object[] getFullElements() {
  -                        return getFullNonNullStringElements();
  -                    }
  -
  -                    public Object[] getOtherElements() {
  -                        return getOtherNonNullStringElements();
  -                    }
  -
  -                };
  +    
  +    public void testpredicatedList() {
  +        Predicate predicate = new Predicate() {
  +            public boolean evaluate(Object o) {
  +                return o instanceof String;
               }
           };
  +        List list =
  +        ListUtils.predicatedList(new ArrayStack(), predicate);
  +        assertTrue("returned object should be a PredicatedList",
  +            list instanceof PredicatedList);
  +        try {
  +            list =
  +            ListUtils.predicatedList(new ArrayStack(), null);
  +            fail("Expecting IllegalArgumentException for null predicate.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
  +        try {
  +            list =
  +            ListUtils.predicatedList(null, predicate);
  +            fail("Expecting IllegalArgumentException for null list.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
       }
   
       public BulkTest bulkTestTypedList() {
  
  
  
  1.8       +26 -27    jakarta-commons/collections/src/test/org/apache/commons/collections/TestSetUtils.java
  
  Index: TestSetUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestSetUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestSetUtils.java	31 Aug 2003 17:28:43 -0000	1.7
  +++ TestSetUtils.java	12 Sep 2003 03:59:00 -0000	1.8
  @@ -65,6 +65,8 @@
   import java.util.HashSet;
   import java.util.Set;
   
  +import org.apache.commons.collections.decorators.PredicatedSet;
  +
   import junit.framework.Test;
   
   
  @@ -87,33 +89,30 @@
   
       public void testNothing() {
       }
  -
  -    public BulkTest bulkTestPredicatedSet() {
  -        return new TestPredicatedCollection("") {
  -
  -            public Collection predicatedCollection() {
  -                Predicate p = getPredicate();
  -                return SetUtils.predicatedSet(new HashSet(), p);
  -            }
  -
  -            public BulkTest bulkTestAll() {
  -                return new TestSet("") {
  -                    public Set makeEmptySet() {
  -                        return (Set)predicatedCollection();
  -                    }
  -
  -                    public Object[] getFullElements() {
  -                        return getFullNonNullStringElements();
  -                    }
  -
  -                    public Object[] getOtherElements() {
  -                        return getOtherNonNullStringElements();
  -                    }
  -
  -                };
  +    
  +    public void testpredicatedSet() {
  +        Predicate predicate = new Predicate() {
  +            public boolean evaluate(Object o) {
  +                return o instanceof String;
               }
           };
  +        Set set = SetUtils.predicatedSet(new HashSet(), predicate);
  +        assertTrue("returned object should be a PredicatedSet",
  +            set instanceof PredicatedSet);
  +        try {
  +            set = SetUtils.predicatedSet(new HashSet(), null);
  +            fail("Expecting IllegalArgumentException for null predicate.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
  +        try {
  +            set = SetUtils.predicatedSet(null, predicate);
  +            fail("Expecting IllegalArgumentException for null set.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
       }
  +
   
       public BulkTest bulkTestTypedSet() {
           return new TestTypedCollection("") {
  
  
  
  1.10      +6 -2      jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestAll.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestAll.java	9 Sep 2003 22:28:36 -0000	1.9
  +++ TestAll.java	12 Sep 2003 03:59:00 -0000	1.10
  @@ -100,6 +100,10 @@
           suite.addTest(TestTransformedSortedSet.suite());
           suite.addTest(TestPredicatedBag.suite());
           suite.addTest(TestPredicatedSortedBag.suite());
  +        suite.addTest(TestPredicatedCollection.suite());
  +        suite.addTest(TestPredicatedBuffer.suite());
  +        suite.addTest(TestPredicatedList.suite());
  +        suite.addTest(TestPredicatedSet.suite());
           
           return suite;
       }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedBuffer.java
  
  Index: TestPredicatedBuffer.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedBuffer.java,v
1.1 2003/09/12 03:59:00 psteitz Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.decorators;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import java.util.ArrayList;
  import java.util.Collection;
  
  import org.apache.commons.collections.ArrayStack;
  import org.apache.commons.collections.Buffer;
  import org.apache.commons.collections.Predicate;
  import org.apache.commons.collections.BufferUnderflowException;
  
  /**
   * Extension of {@link TestPredicatedCollection} for exercising the 
   * {@link PredicatedBuffer} implementation.
   *
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/09/12 03:59:00 $
   * 
   * @author Phil Steitz
   */
  public class TestPredicatedBuffer extends TestPredicatedCollection {
      
      public TestPredicatedBuffer(String testName) {
          super(testName);
      }
      
      public static Test suite() {
          return new TestSuite(TestPredicatedBuffer.class);
      }
      
      public static void main(String args[]) {
          String[] testCaseName = { TestPredicatedBuffer.class.getName()};
          junit.textui.TestRunner.main(testCaseName);
      }
      
      //---------------------------------------------------------------
      
      protected Buffer decorateBuffer(Buffer buffer, Predicate predicate) {
          return PredicatedBuffer.decorate(buffer, predicate);
      }
      
      public Collection makeCollection() {
          return decorateBuffer(new ArrayStack(), truePredicate);
      }
      
      public Collection makeConfirmedCollection() {
          return new ArrayStack();
      }
      
      public Collection makeConfirmedFullCollection() {
          ArrayStack list = new ArrayStack();
          list.addAll(java.util.Arrays.asList(getFullElements()));
          return list;
      }
      
      //------------------------------------------------------------
      
      public Buffer makeTestBuffer() {
          return decorateBuffer(new ArrayStack(), testPredicate);
      }
      
      public void testGet() {
          Buffer buffer = makeTestBuffer();
          try {
              Object o = buffer.get();
              fail("Expecting BufferUnderflowException");
          } catch (BufferUnderflowException ex) {
              // expected
          }
          buffer.add("one");
          buffer.add("two");
          buffer.add("three");
          assertEquals("Buffer get", buffer.get(), "three");
      }
      
      public void testRemove() {
          Buffer buffer = makeTestBuffer();
          buffer.add("one");
          assertEquals("Buffer get", buffer.remove(), "one");
          try {
              buffer.remove();
              fail("Expecting BufferUnderflowException");
          } catch (BufferUnderflowException ex) {
              // expected
          }      
      }
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedCollection.java
  
  Index: TestPredicatedCollection.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.collections.decorators;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
  import java.util.Arrays;
  import org.apache.commons.collections.TestCollection;
  import org.apache.commons.collections.Predicate;
  import org.apache.commons.collections.PredicateUtils;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  /**
   * Extension of {@link TestCollection} for exercising the 
   * {@link PredicatedCollection} implementation.
   *
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/09/12 03:59:00 $
   * 
   * @author Phil Steitz
   */
  public class TestPredicatedCollection extends TestCollection {
  
      public TestPredicatedCollection(String name) {
          super(name);
      }
      
      public static Test suite() {
          return new TestSuite(TestPredicatedCollection.class);
      }
  
      public static void main(String args[]) {
          String[] testCaseName = { TestPredicatedCollection.class.getName()};
          junit.textui.TestRunner.main(testCaseName);
      }
   
   //------------------------------------------------------------------------
          
      protected Predicate truePredicate = PredicateUtils.truePredicate();
      
      protected Collection decorateCollection(Collection collection, 
          Predicate predicate) {
          return PredicatedCollection.decorate(collection, predicate);
      }
      
      public Collection makeCollection() {
          return decorateCollection(new ArrayList(), truePredicate);
      }
      
      public Collection makeConfirmedCollection() {
          return new ArrayList();
      }
      
      protected Object[] getFullElements() {
          return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
      }
      
      protected Collection makeFullCollection() {
          List list = new ArrayList();
          list.addAll(Arrays.asList(getFullElements()));
          return decorateCollection(list, truePredicate);
      }
      
      protected Collection makeConfirmedFullCollection() {
          List list = new ArrayList();
          list.addAll(Arrays.asList(getFullElements()));
          return list;
      }
  
   //-----------------------------------------------------------------
      protected Predicate testPredicate =  
          new Predicate() {
              public boolean evaluate(Object o) {
                  return o instanceof String;
              }
          };
      
      public Collection makeTestCollection() {
          return decorateCollection(new ArrayList(), testPredicate);
      }
       
      public void testIllegalAdd() {
          Collection c = makeTestCollection();
          Integer i = new Integer(3);
          try {
              c.add(i);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains(i));   
      }
  
      public void testIllegalAddAll() {
          Collection c = makeTestCollection();
          List elements = new ArrayList();
          elements.add("one");
          elements.add("two");
          elements.add(new Integer(3));
          elements.add("four");
          try {
              c.addAll(elements);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("one"));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("two"));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains(new Integer(3)));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("four"));   
      }
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedList.java
  
  Index: TestPredicatedList.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedList.java,v
1.1 2003/09/12 03:59:00 psteitz Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.decorators;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.commons.collections.TestList;
  import org.apache.commons.collections.Predicate;
  import org.apache.commons.collections.PredicateUtils;
  /**
   * Extension of {@link TestList} for exercising the 
   * {@link PredicatedList} implementation.
   *
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/09/12 03:59:00 $
   * 
   * @author Phil Steitz
   */
  public class TestPredicatedList extends TestList{
      
      public TestPredicatedList(String testName) {
          super(testName);
      }
      
      public static Test suite() {
          return new TestSuite(TestPredicatedList.class);
      }
      
      public static void main(String args[]) {
          String[] testCaseName = { TestPredicatedList.class.getName()};
          junit.textui.TestRunner.main(testCaseName);
      }
      
   //-------------------------------------------------------------------
      
      protected Predicate truePredicate = PredicateUtils.truePredicate();
      
      protected List decorateList(List list, Predicate predicate) {
          return PredicatedList.decorate(list, predicate);
      }
      
      public List makeEmptyList() {
          return decorateList(new ArrayList(), truePredicate);
      }
      
      protected Object[] getFullElements() {
          return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
      }
      
  //--------------------------------------------------------------------   
      
       protected Predicate testPredicate =  
          new Predicate() {
              public boolean evaluate(Object o) {
                  return o instanceof String;
              }
          };      
      
      public List makeTestList() {
          return decorateList(new ArrayList(), testPredicate);
      }
      
      public void testIllegalAdd() {
          List list = makeTestList();
          Integer i = new Integer(3);
          try {
              list.add(i);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !list.contains(i));   
      }
  
      public void testIllegalAddAll() {
          List list = makeTestList();
          List elements = new ArrayList();
          elements.add("one");
          elements.add("two");
          elements.add(new Integer(3));
          elements.add("four");
          try {
              list.addAll(0,elements);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("List shouldn't contain illegal element", 
           !list.contains("one"));   
          assertTrue("List shouldn't contain illegal element", 
           !list.contains("two"));   
          assertTrue("List shouldn't contain illegal element", 
           !list.contains(new Integer(3)));   
          assertTrue("List shouldn't contain illegal element", 
           !list.contains("four"));   
      }
      
      public void testIllegalSet() {
          List list = makeTestList();
          try {
              list.set(0,new Integer(3));
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
      }
      
      public void testLegalAddAll() {
          List list = makeTestList();
          list.add("zero");
          List elements = new ArrayList();
          elements.add("one");
          elements.add("two");
          elements.add("three");
          list.addAll(1,elements);
          assertTrue("List should contain legal element", 
           list.contains("zero"));   
          assertTrue("List should contain legal element", 
           list.contains("one"));   
          assertTrue("List should contain legal element", 
           list.contains("two"));   
          assertTrue("List should contain legal element", 
           list.contains("three"));   
      }       
          
  }
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedSet.java
  
  Index: TestPredicatedSet.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestPredicatedSet.java,v
1.1 2003/09/12 03:59:00 psteitz Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections.decorators;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import java.util.HashSet;
  import java.util.Set;
  
  import org.apache.commons.collections.TestSet;
  import org.apache.commons.collections.Predicate;
  import org.apache.commons.collections.PredicateUtils;
  /**
   * Extension of {@link TestSet} for exercising the 
   * {@link PredicatedSet} implementation.
   *
   * @since Commons Collections 3.0
   * @version $Revision: 1.1 $ $Date: 2003/09/12 03:59:00 $
   * 
   * @author Phil Steitz
   */
  public class TestPredicatedSet extends TestSet{
      
      public TestPredicatedSet(String testName) {
          super(testName);
      }
      
      public static Test suite() {
          return new TestSuite(TestPredicatedSet.class);
      }
      
      public static void main(String args[]) {
          String[] testCaseName = { TestPredicatedSet.class.getName()};
          junit.textui.TestRunner.main(testCaseName);
      }
      
   //-------------------------------------------------------------------
      
      protected Predicate truePredicate = PredicateUtils.truePredicate();
      
      protected Set decorateSet(Set set, Predicate predicate) {
          return PredicatedSet.decorate(set, predicate);
      }
      
      public Set makeEmptySet() {
          return decorateSet(new HashSet(), truePredicate);
      }
      
      protected Object[] getFullElements() {
          return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
      }
      
  //--------------------------------------------------------------------   
      
       protected Predicate testPredicate =  
          new Predicate() {
              public boolean evaluate(Object o) {
                  return o instanceof String;
              }
          };      
      
      public Set makeTestSet() {
          return decorateSet(new HashSet(), testPredicate);
      }
      
      public void testGetSet() {
           Set set = makeTestSet();
          assertTrue("returned set should not be null",
              ((PredicatedSet) set).getSet() != null);
      }
      
      public void testIllegalAdd() {
          Set set = makeTestSet();
          Integer i = new Integer(3);
          try {
              set.add(i);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !set.contains(i));   
      }
  
      public void testIllegalAddAll() {
          Set set = makeTestSet();
          Set elements = new HashSet();
          elements.add("one");
          elements.add("two");
          elements.add(new Integer(3));
          elements.add("four");
          try {
              set.addAll(elements);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("Set shouldn't contain illegal element", 
           !set.contains("one"));   
          assertTrue("Set shouldn't contain illegal element", 
           !set.contains("two"));   
          assertTrue("Set shouldn't contain illegal element", 
           !set.contains(new Integer(3)));   
          assertTrue("Set shouldn't contain illegal element", 
           !set.contains("four"));   
      }
          
  }
  
  

Mime
View raw message