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 TestCollectionUtils.java
Date Mon, 22 Sep 2003 08:22:53 GMT
psteitz     2003/09/22 01:22:53

  Modified:    collections/src/test/org/apache/commons/collections
                        TestCollectionUtils.java
  Log:
  Added tests for collect, decorator factories.
  
  Revision  Changes    Path
  1.21      +70 -4     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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TestCollectionUtils.java	21 Sep 2003 20:56:51 -0000	1.20
  +++ TestCollectionUtils.java	22 Sep 2003 08:22:53 -0000	1.21
  @@ -78,7 +78,10 @@
   import junit.framework.TestSuite;
   
   import org.apache.commons.collections.decorators.PredicatedCollection;
  +import org.apache.commons.collections.decorators.SynchronizedCollection;
   import org.apache.commons.collections.decorators.TransformedCollection;
  +import org.apache.commons.collections.decorators.UnmodifiableCollection;
  + 
   
   /**
    * Tests for CollectionUtils.
  @@ -658,6 +661,44 @@
           assertTrue(output.contains("Three"));
           assertTrue(output.contains("Four"));
       }
  +    
  +    public void testCollect() {
  +        Transformer transformer = TransformerUtils.constantTransformer("z");
  +        Collection collection = CollectionUtils.collect(_a, transformer);
  +        assertTrue(collection.size() == _a.size());
  +        assertTrue(_a.contains("a") && ! _a.contains("z"));
  +        assertTrue(collection.contains("z") && !collection.contains("a"));
  +        
  +        collection = new ArrayList();
  +        CollectionUtils.collect(_a, transformer, collection);
  +        assertTrue(collection.size() == _a.size());
  +        assertTrue(_a.contains("a") && ! _a.contains("z"));
  +        assertTrue(collection.contains("z") && !collection.contains("a"));
  +        
  +        Iterator iterator = null;
  +        collection = new ArrayList();
  +        CollectionUtils.collect(iterator, transformer, collection);
  +        
  +        iterator = _a.iterator();
  +        CollectionUtils.collect(iterator, transformer, collection);
  +        assertTrue(collection.size() == _a.size());
  +        assertTrue(_a.contains("a") && ! _a.contains("z"));
  +        assertTrue(collection.contains("z") && !collection.contains("a")); 
  +        
  +        iterator = _a.iterator();
  +        collection = CollectionUtils.collect(iterator, transformer);
  +        assertTrue(collection.size() == _a.size());
  +        assertTrue(collection.contains("z") && !collection.contains("a")); 
  +        collection = CollectionUtils.collect((Iterator) null, (Transformer) null);
  +        assertTrue(collection.size() == 0);
  +           
  +        int size = _a.size();
  +        CollectionUtils.collect((Collection) null, transformer, _a);
  +        assertTrue(_a.size() == size && _a.contains("a"));
  +        CollectionUtils.collect(_b, null, _a);
  +        assertTrue(_a.size() == size && _a.contains("a"));
  +        
  +    }
   
       Transformer TRANSFORM_TO_INTEGER = new Transformer() {
           public Object transform(Object input) {
  @@ -880,4 +921,29 @@
               // expected
           }             
       }
  +     
  +    public void testSynchronizedCollection() {
  +        Collection col = CollectionUtils.synchronizedCollection(new ArrayList());
  +        assertTrue("Returned object should be a SynchronizedCollection.",
  +            col instanceof SynchronizedCollection);
  +        try {
  +            col = CollectionUtils.synchronizedCollection(null);
  +            fail("Expecting IllegalArgumentException for null collection.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }  
  +    }
  +    
  +    public void testUnmodifiableCollection() {
  +        Collection col = CollectionUtils.unmodifiableCollection(new ArrayList());
  +        assertTrue("Returned object should be a UnmodifiableCollection.",
  +            col instanceof UnmodifiableCollection);
  +        try {
  +            col = CollectionUtils.unmodifiableCollection(null);
  +            fail("Expecting IllegalArgumentException for null collection.");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }  
  +    }
  +
   }
  
  
  

Mime
View raw message