commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestListUtils.java TestSetUtils.java
Date Fri, 04 Apr 2003 20:42:03 GMT
scolebourne    2003/04/04 12:42:03

  Modified:    collections/src/test/org/apache/commons/collections
                        TestListUtils.java TestSetUtils.java
  Log:
  Add new equals and hashCode methods that aid implementors of the interfaces
  from Neil O'Toole
  
  Revision  Changes    Path
  1.6       +40 -7     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestListUtils.java	12 Oct 2002 22:36:22 -0000	1.5
  +++ TestListUtils.java	4 Apr 2003 20:42:02 -0000	1.6
  @@ -61,12 +61,18 @@
   package org.apache.commons.collections;
   
   import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.Collection;
   import java.util.List;
   
   import junit.framework.Test;
   
  -
  +/**
  + * Tests for ListUtils.
  + * 
  + * @author Stephen Colebourne
  + * @author Neil O'Toole
  + */
   public class TestListUtils extends BulkTest {
   
       public TestListUtils(String name) {
  @@ -126,7 +132,34 @@
           assertEquals(6, list.size());
       }
   
  -
  +	public void testEquals() {
  +		Collection data = Arrays.asList( new String[] { "a", "b", "c" });
  +		
  +		List a = new ArrayList( data );
  +		List b = new ArrayList( data );
  +		
  +        assertEquals(true, a.equals(b));
  +        assertEquals(true, ListUtils.equals(a, b));
  +        a.clear();
  +        assertEquals(false, ListUtils.equals(a, b));
  +        assertEquals(false, ListUtils.equals(a, null));
  +        assertEquals(false, ListUtils.equals(null, b));
  +        assertEquals(true, ListUtils.equals(null, null));
  +	}
  +	
  +	public void testHashCode() {
  +		Collection data = Arrays.asList( new String[] { "a", "b", "c" });
  +			
  +		List a = new ArrayList( data );
  +		List b = new ArrayList( data );
  +		
  +        assertEquals(true, a.hashCode() == b.hashCode());
  +        assertEquals(true, a.hashCode() == ListUtils.hashCode(a));
  +        assertEquals(true, b.hashCode() == ListUtils.hashCode(b));
  +        assertEquals(true, ListUtils.hashCode(a) == ListUtils.hashCode(b));
  +        a.clear();
  +        assertEquals(false, ListUtils.hashCode(a) == ListUtils.hashCode(b));
  +        assertEquals(0, ListUtils.hashCode(null));
  +	}	
  +	
   }
  -
  -
  
  
  
  1.4       +37 -6     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestSetUtils.java	19 Feb 2003 20:33:11 -0000	1.3
  +++ TestSetUtils.java	4 Apr 2003 20:42:03 -0000	1.4
  @@ -60,6 +60,7 @@
    */
   package org.apache.commons.collections;
   
  +import java.util.Arrays;
   import java.util.Collection;
   import java.util.HashSet;
   import java.util.Set;
  @@ -68,7 +69,10 @@
   
   
   /**
  - *  Tests for SetUtils.
  + * Tests for SetUtils.
  + * 
  + * @author Stephen Colebourne
  + * @author Neil O'Toole
    */
   public class TestSetUtils extends BulkTest {
   
  @@ -110,7 +114,34 @@
           };
       }
   
  +    public void testEquals() {
  +        Collection data = Arrays.asList( new String[] { "a", "b", "c" });
  +        
  +        Set a = new HashSet( data );
  +        Set b = new HashSet( data );
  +        
  +        assertEquals(true, a.equals(b));
  +        assertEquals(true, SetUtils.equals(a, b));
  +        a.clear();
  +        assertEquals(false, SetUtils.equals(a, b));
  +        assertEquals(false, SetUtils.equals(a, null));
  +        assertEquals(false, SetUtils.equals(null, b));
  +        assertEquals(true, SetUtils.equals(null, null));
  +    }
  +    
  +    public void testHashCode() {
  +        Collection data = Arrays.asList( new String[] { "a", "b", "c" });
  +            
  +        Set a = new HashSet( data );
  +        Set b = new HashSet( data );
  +        
  +        assertEquals(true, a.hashCode() == b.hashCode());
  +        assertEquals(true, a.hashCode() == SetUtils.hashCode(a));
  +        assertEquals(true, b.hashCode() == SetUtils.hashCode(b));
  +        assertEquals(true, SetUtils.hashCode(a) == SetUtils.hashCode(b));
  +        a.clear();
  +        assertEquals(false, SetUtils.hashCode(a) == SetUtils.hashCode(b));
  +        assertEquals(0, SetUtils.hashCode(null));
  +    }   
   
   }
  -
  -
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message