commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/comparators TestComparableComparator.java TestComparator.java
Date Fri, 01 Mar 2002 18:36:21 GMT
morgand     02/03/01 10:36:21

  Modified:    collections/src/test/org/apache/commons/collections
                        TestAll.java TestObject.java
  Added:       collections/src/test/org/apache/commons/collections/comparators
                        TestComparableComparator.java TestComparator.java
  Log:
  added unit tests for Comparators
  
  Revision  Changes    Path
  1.21      +6 -4      jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TestAll.java	26 Feb 2002 17:31:51 -0000	1.20
  +++ TestAll.java	1 Mar 2002 18:36:21 -0000	1.21
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java,v
1.20 2002/02/26 17:31:51 morgand Exp $
  - * $Revision: 1.20 $
  - * $Date: 2002/02/26 17:31:51 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java,v
1.21 2002/03/01 18:36:21 morgand Exp $
  + * $Revision: 1.21 $
  + * $Date: 2002/03/01 18:36:21 $
    *
    * ====================================================================
    *
  @@ -61,12 +61,13 @@
   
   package org.apache.commons.collections;
   
  +import org.apache.commons.collections.comparators.*;
   import junit.framework.*;
   
   /**
    * Entry point for all Collections tests.
    * @author Rodney Waldhoff
  - * @version $Id: TestAll.java,v 1.20 2002/02/26 17:31:51 morgand Exp $
  + * @version $Id: TestAll.java,v 1.21 2002/03/01 18:36:21 morgand Exp $
    */
   public class TestAll extends TestCase {
       public TestAll(String testName) {
  @@ -80,6 +81,7 @@
           suite.addTest(TestArrayStack.suite());
           suite.addTest(TestBeanMap.suite());
           suite.addTest(TestCollectionUtils.suite());
  +        suite.addTest(TestComparableComparator.suite());
           suite.addTest(TestCursorableLinkedList.suite());
           suite.addTest(TestDoubleOrderedMap.suite());
           suite.addTest(TestExtendedProperties.suite());
  
  
  
  1.10      +33 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestObject.java	26 Feb 2002 20:52:17 -0000	1.9
  +++ TestObject.java	1 Mar 2002 18:36:21 -0000	1.10
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestObject.java,v
1.9 2002/02/26 20:52:17 morgand Exp $
  - * $Revision: 1.9 $
  - * $Date: 2002/02/26 20:52:17 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestObject.java,v
1.10 2002/03/01 18:36:21 morgand Exp $
  + * $Revision: 1.10 $
  + * $Date: 2002/03/01 18:36:21 $
    *
    * ====================================================================
    *
  @@ -91,7 +91,7 @@
    * test case (method) your {@link Object} fails.
    *
    * @author Rodney Waldhoff
  - * @version $Id: TestObject.java,v 1.9 2002/02/26 20:52:17 morgand Exp $
  + * @version $Id: TestObject.java,v 1.10 2002/03/01 18:36:21 morgand Exp $
    */
   public abstract class TestObject extends TestCase {
       public TestObject(String testName) {
  @@ -261,6 +261,27 @@
           return retval.toString();
       }
   
  +    /**
  +     * Override this method if a subclass is testing a 
  +     * Collections that cannot serialize an "empty" Collection
  +     * (e.g. Comparators have no contents)
  +     * 
  +     * @return true
  +     */
  +    public boolean supportsEmptyCollections() {
  +        return true;
  +    }
  +
  +    /**
  +     * Override this method if a subclass is testing a 
  +     * Collections that cannot serialize a "full" Collection
  +     * (e.g. Comparators have no contents)
  +     * 
  +     * @return true
  +     */
  +    public boolean supportsFullCollections() {
  +        return true;
  +    }
   
       /**
        * If the test object is serializable, confirm that 
  @@ -268,6 +289,10 @@
        * 
        */
       public void testCanonicalEmptyCollectionExists() {
  +        if (!supportsEmptyCollections()) {
  +            return;
  +        }
  +
           Object object = makeObject();
           if (!(object instanceof Serializable)) {
               return;
  @@ -283,6 +308,10 @@
        * 
        */
       public void testCanonicalFullCollectionExists() {
  +        if (!supportsFullCollections()) {
  +            return;
  +        }
  +        
           Object object = makeObject();
           if (!(object instanceof Serializable)) {
               return;
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java
  
  Index: TestComparableComparator.java
  ===================================================================
  package org.apache.commons.collections.comparators;
  
  import java.util.Comparator;
  import java.util.LinkedList;
  import java.util.List;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  public class TestComparableComparator extends TestComparator {
  
      public TestComparableComparator(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestComparableComparator.class);
      }
  
      public Comparator makeComparator() {
          return new ComparableComparator();
      }
  
      public List getComparableObjectsOrdered() {
          List list = new LinkedList();
          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;
      }
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparator.java
  
  Index: TestComparator.java
  ===================================================================
  package org.apache.commons.collections.comparators;
  
  import java.io.Serializable;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.LinkedList;
  import java.util.List;
  
  import org.apache.commons.collections.CollectionUtils;
  import org.apache.commons.collections.TestObject;
  
  public abstract class TestComparator extends TestObject {
  
      public TestComparator(String testName) {
          super(testName);
      }
  
      public abstract Comparator makeComparator();
      public abstract List getComparableObjectsOrdered();
  
      public Object makeObject() {
          return makeComparator();
      }
  
      public void reverseObjects(List list) {
          Collections.reverse(list);
      }
  
      /**
       * Sort object according to the given Comparator.
       * 
       * @param list       List to sort
       * @param comparator sorting comparator
       */
      public void sortObjects(List list, Comparator comparator) {
  
          Collections.sort(list,comparator);
  
      }
  
      public boolean supportsEmptyCollections() {
          return false;
      }
  
      public boolean supportsFullCollections() {
          return false;
      }
  
      public void testEmptyListSort() {
          List list = new LinkedList();
          sortObjects(list,makeComparator());
  
          List list2 = new LinkedList();
          
          assertTrue("Comparator cannot sort empty lists",
                     list2.equals(list));
      }
  
      public void testRandomListSort() {
          Comparator comparator = makeComparator();
  
          List randomList = getComparableObjectsOrdered();
          reverseObjects(randomList);
          sortObjects(randomList,comparator);
  
          List orderedList = getComparableObjectsOrdered();
  
          assertTrue("Comparator did not reorder the List correctly",
                     orderedList.equals(randomList));
  
      }
  
      /**
       * Nearly all Comparators should be Serializable.
       */
      public void testComparatorIsSerializable() {
          Comparator comparator = makeComparator();
          assertTrue("This comparator should be Serializable.",
                     comparator instanceof Serializable);
      }
  
  }
  
  
  

--
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