commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/comparators TestComparatorChain.java TestNullComparator.java TestReverseComparator.java
Date Tue, 07 Jan 2003 23:44:21 GMT
rwaldhoff    2003/01/07 15:44:20

  Modified:    collections/src/test/org/apache/commons/collections
                        TestBeanMap.java TestCursorableLinkedList.java
                        TestObject.java
               collections/src/test/org/apache/commons/collections/comparators
                        TestComparatorChain.java TestNullComparator.java
                        TestReverseComparator.java
  Log:
  add base testSerializeDeserializeThenCompare test, modify concrete TestCases so that they
pass this test (or when necessary, skip them)
  this tests the Comparator.equals contract, among others
  
  Revision  Changes    Path
  1.8       +10 -7     jakarta-commons/collections/src/test/org/apache/commons/collections/TestBeanMap.java
  
  Index: TestBeanMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBeanMap.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestBeanMap.java	10 Aug 2002 02:05:20 -0000	1.7
  +++ TestBeanMap.java	7 Jan 2003 23:44:19 -0000	1.8
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -60,9 +60,10 @@
    */
   package org.apache.commons.collections;
   
  +import java.io.Serializable;
   import java.util.Map;
   
  -import junit.framework.*;
  +import junit.framework.Test;
   
   /**
    * Test cases for BeanMap
  @@ -98,7 +99,7 @@
   */
   
   
  -    public static class BeanWithProperties {
  +    public static class BeanWithProperties implements Serializable {
           private int someInt;
           private long someLong;
           private double someDouble;
  @@ -328,7 +329,9 @@
            "TestBeanMap.bulkTestMapValues.testCanonicalEmptyCollectionExists",
            "TestBeanMap.bulkTestMapValues.testCanonicalFullCollectionExists",
            "TestBeanMap.bulkTestMapEntrySet.testSimpleSerialization",
  -         "TestBeanMap.bulkTestMapKeySet.testSimpleSerialization"
  +         "TestBeanMap.bulkTestMapKeySet.testSimpleSerialization",
  +         "TestBeanMap.bulkTestMapEntrySet.testSerializeDeserializeThenCompare",
  +         "TestBeanMap.bulkTestMapKeySet.testSerializeDeserializeThenCompare"
           };
       }
   
  
  
  
  1.7       +6 -5      jakarta-commons/collections/src/test/org/apache/commons/collections/TestCursorableLinkedList.java
  
  Index: TestCursorableLinkedList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCursorableLinkedList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestCursorableLinkedList.java	21 Jun 2002 03:32:06 -0000	1.6
  +++ TestCursorableLinkedList.java	7 Jan 2003 23:44:19 -0000	1.7
  @@ -966,7 +966,8 @@
             ".testFullListCompatibility", 
             ".testSimpleSerialization",
             ".testCanonicalEmptyCollectionExists",
  -          ".testCanonicalFullCollectionExists"
  +          ".testCanonicalFullCollectionExists",
  +          ".testSerializeDeserializeThenCompare"
           };
           for (int i = 0; i < ignored.length; i++) {
               list.add(prefix + bulk + ignored[i]);
  
  
  
  1.17      +19 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestObject.java
  
  Index: TestObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestObject.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- TestObject.java	7 Jan 2003 15:18:15 -0000	1.16
  +++ TestObject.java	7 Jan 2003 23:44:19 -0000	1.17
  @@ -84,7 +84,7 @@
    * test case (method) your {@link Object} fails.
    *
    * @author Rodney Waldhoff
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
   public abstract class TestObject extends BulkTest {
       public TestObject(String testName) {
  @@ -138,6 +138,21 @@
           if(obj1.equals(obj2)) {
               assertEquals("[2] When two objects are equal, their hashCodes should be also.",obj1.hashCode(),obj2.hashCode());
               assertTrue("When obj1.equals(obj2) is true, then obj2.equals(obj1) should also
be true", obj2.equals(obj1));
  +        }
  +    }
  +
  +    public void testSerializeDeserializeThenCompare() throws Exception {
  +        Object obj = makeObject();
  +        if(obj instanceof Serializable) {
  +            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  +            ObjectOutputStream out = new ObjectOutputStream(buffer);
  +            out.writeObject(obj);
  +            out.close();
  +            
  +            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
  +            Object dest = in.readObject();
  +            in.close();
  +            assertEquals("obj != deserialize(serialize(obj))",obj,dest);
           }
       }
   
  
  
  
  1.4       +70 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparatorChain.java
  
  Index: TestComparatorChain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparatorChain.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestComparatorChain.java	12 Oct 2002 22:36:23 -0000	1.3
  +++ TestComparatorChain.java	7 Jan 2003 23:44:20 -0000	1.4
  @@ -1,3 +1,59 @@
  +/* 
  + * $Id$
  + * ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001-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 acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache Commons" 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.comparators;
   
   import java.io.Serializable;
  @@ -18,10 +74,6 @@
           return new TestSuite(TestComparatorChain.class);
       }
   
  -    /**
  -     * 
  -     * @return 
  -     */
       public Comparator makeComparator() {
           ComparatorChain chain = new ComparatorChain(new ColumnComparator(0));
           chain.addComparator(new ColumnComparator(1),true); // reverse the second column
  @@ -159,5 +211,19 @@
   
               return 0;
           }
  +        
  +        public int hashCode() {
  +            return colIndex;
  +        }
  +        
  +        public boolean equals(Object that) {
  +            if(that instanceof ColumnComparator) {
  +                return colIndex == ((ColumnComparator)that).colIndex;
  +            } else {
  +                return false;
  +            }
  +        }
  +        
  +        private static final long serialVersionUID = -2284880866328872105L;
       }
   }
  
  
  
  1.4       +29 -29    jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestNullComparator.java
  
  Index: TestNullComparator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestNullComparator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestNullComparator.java	12 Oct 2002 22:36:23 -0000	1.3
  +++ TestNullComparator.java	7 Jan 2003 23:44:20 -0000	1.4
  @@ -74,10 +74,10 @@
       }
   
       public static Test suite() {
  -	TestSuite suite = new TestSuite(TestNullComparator.class.getName());
  -	suite.addTest(new TestSuite(TestNullComparator1.class));
  -	suite.addTest(new TestSuite(TestNullComparator2.class));
  -	return suite;
  +        TestSuite suite = new TestSuite(TestNullComparator.class.getName());
  +        suite.addTest(new TestSuite(TestNullComparator1.class));
  +        suite.addTest(new TestSuite(TestNullComparator2.class));
  +        return suite;
       }
   
       /**
  @@ -94,7 +94,7 @@
   	}
   	
   	public List getComparableObjectsOrdered() {
  -	    List list = new LinkedList();
  +        List list = new LinkedList();
   	    list.add(new Integer(1));
   	    list.add(new Integer(2));
   	    list.add(new Integer(3));
  @@ -113,28 +113,28 @@
        *  Test the NullComparator with nulls low using the comparable comparator
        **/
       public static class TestNullComparator2 extends TestNullComparator {
  -
  -	public TestNullComparator2(String testName) {
  -	    super(testName);
  -	}
  -
  -	public Comparator makeComparator() {
  -	    return new NullComparator(false);
  -	}
  -	
  -	public List getComparableObjectsOrdered() {
  -	    List list = new LinkedList();
  -	    list.add(null);
  -	    list.add(new Integer(1));
  -	    list.add(new Integer(2));
  -	    list.add(new Integer(3));
  -	    list.add(new Integer(4));
  -	    list.add(new Integer(5));
  -	    return list;
  -	}
  -
  -	public String getCanonicalComparatorName(Object object) {
  -	    return super.getCanonicalComparatorName(object) + "2";
  -	}
  +        
  +        public TestNullComparator2(String testName) {
  +            super(testName);
  +        }
  +        
  +        public Comparator makeComparator() {
  +            return new NullComparator(false);
  +        }
  +        
  +        public List getComparableObjectsOrdered() {
  +            List list = new LinkedList();
  +            list.add(null);
  +            list.add(new Integer(1));
  +            list.add(new Integer(2));
  +            list.add(new Integer(3));
  +            list.add(new Integer(4));
  +            list.add(new Integer(5));
  +            return list;
  +        }
  +        
  +        public String getCanonicalComparatorName(Object object) {
  +            return super.getCanonicalComparatorName(object) + "2";
  +        }
       }
   }
  
  
  
  1.4       +80 -1     jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestReverseComparator.java
  
  Index: TestReverseComparator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestReverseComparator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestReverseComparator.java	12 Oct 2002 22:36:23 -0000	1.3
  +++ TestReverseComparator.java	7 Jan 2003 23:44:20 -0000	1.4
  @@ -1,5 +1,65 @@
  +/* 
  + * $Id$
  + * ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001-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 acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache Commons" 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.comparators;
   
  +import java.io.ByteArrayInputStream;
  +import java.io.ByteArrayOutputStream;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.util.Collections;
   import java.util.Comparator;
   import java.util.LinkedList;
  @@ -21,7 +81,7 @@
       /**
        * For the purposes of this test, return a 
        * ReverseComparator that wraps the java.util.Collections.reverseOrder()
  -     * Comparator.  The resulting comparator shouls
  +     * Comparator.  The resulting comparator should
        * sort according to natural Order.  (Note: we wrap
        * a Comparator taken from the JDK so that we can
        * save a "canonical" form in CVS.
  @@ -40,6 +100,25 @@
           list.add(new Integer(4));
           list.add(new Integer(5));
           return list;
  +    }
  +
  +    /** 
  +     * Override this inherited test since Collections.reverseOrder
  +     * doesn't adhere to the "soft" Comparator contract, and we've
  +     * already "cannonized" the comparator returned by makeComparator.
  +     */
  +    public void testSerializeDeserializeThenCompare() throws Exception {
  +        Comparator comp = new ReverseComparator(new ComparableComparator());
  +
  +        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  +        ObjectOutputStream out = new ObjectOutputStream(buffer);
  +        out.writeObject(comp);
  +        out.close();
  +            
  +        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
  +        Object dest = in.readObject();
  +        in.close();
  +        assertEquals("obj != deserialize(serialize(obj))",comp,dest);
       }
   
   }
  
  
  

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


Mime
View raw message