rwaldhoff    2003/11/24 15:11:48

  Modified:    functor/src/test/org/apache/commons/functor/core/collection
                        TestIsEmpty.java
               functor/src/java/org/apache/commons/functor/core/collection
                        IsEmpty.java
  Log:
  support Maps in IsEmpty, add tests
  
  Revision  Changes    Path
  1.5       +13 -4     
jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestIsEmpty.java
  
  Index: TestIsEmpty.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/collection/TestIsEmpty.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIsEmpty.java  24 Nov 2003 21:38:39 -0000      1.4
  +++ TestIsEmpty.java  24 Nov 2003 23:11:48 -0000      1.5
  @@ -58,8 +58,10 @@
   
   import java.util.ArrayList;
   import java.util.Collections;
  +import java.util.HashMap;
   import java.util.HashSet;
   import java.util.List;
  +import java.util.Map;
   import java.util.Set;
   
   import junit.framework.Test;
  @@ -137,8 +139,8 @@
       public void testTestNonCollection() throws Exception {
           try {
               IsEmpty.instance().test(new Integer(3));
  -            fail("Expected ClassCastException");
  -        } catch(ClassCastException e) {
  +            fail("Expected IllegalArgumentException");
  +        } catch(IllegalArgumentException e) {
               // expected
           }
       }
  @@ -153,6 +155,13 @@
       public void testTestString() throws Exception {
           assertTrue(! IsEmpty.instance().test("xyzzy"));
           assertTrue(IsEmpty.instance().test(""));
  +    }
  +
  +    public void testTestMap() throws Exception {
  +        Map map = new HashMap();
  +        assertTrue(IsEmpty.instance().test(map));
  +        map.put("x","y");
  +        assertTrue(! IsEmpty.instance().test(map));
       }
   
       public void testEquals() throws Exception {
  
  
  
  1.4       +14 -7     
jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/collection/IsEmpty.java
  
  Index: IsEmpty.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/collection/IsEmpty.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IsEmpty.java      24 Nov 2003 21:38:39 -0000      1.3
  +++ IsEmpty.java      24 Nov 2003 23:11:48 -0000      1.4
  @@ -59,6 +59,7 @@
   import java.io.Serializable;
   import java.lang.reflect.Array;
   import java.util.Collection;
  +import java.util.Map;
   
   import org.apache.commons.functor.UnaryPredicate;
   
  @@ -78,15 +79,17 @@
       
       public boolean test(Object obj) {
           if(obj instanceof Collection) {
  -            return test((Collection)obj);
  +            return testCollection((Collection)obj);
  +        } else if(obj instanceof Map) {
  +            return testMap((Map)obj);
           } else if(obj instanceof String) {
  -            return test((String)obj);
  +            return testString((String)obj);
           } else if(null != obj && obj.getClass().isArray()) {
               return testArray(obj);
           } else if(null == obj){
               throw new NullPointerException("Argument must not be null");
           } else {
  -            throw new ClassCastException("Expected Collection, String or Array, 
found " + obj);
  +            throw new IllegalArgumentException("Expected Collection, Map, String or 
Array, found " + obj.getClass());
           } 
       }
   
  @@ -111,11 +114,15 @@
           return "IsEmpty()";
       }
   
  -    private boolean test(Collection col) {
  +    private boolean testCollection(Collection col) {
           return col.isEmpty();
       }
       
  -    private boolean test(String str) {
  +    private boolean testMap(Map map) {
  +        return map.isEmpty();
  +    }
  +    
  +    private boolean testString(String str) {
           return 0 == str.length();
       }
       
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to