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/comparators AbstractTestComparator.java TestComparatorChain.java TestBooleanComparator.java TestReverseComparator.java TestNullComparator.java TestFixedOrderComparator.java TestComparableComparator.java TestComparator.java
Date Wed, 01 Oct 2003 22:14:48 GMT
scolebourne    2003/10/01 15:14:48

  Modified:    collections/src/test/org/apache/commons/collections/comparators
                        TestComparatorChain.java TestBooleanComparator.java
                        TestReverseComparator.java TestNullComparator.java
                        TestFixedOrderComparator.java
                        TestComparableComparator.java
  Added:       collections/src/test/org/apache/commons/collections/comparators
                        AbstractTestComparator.java
  Removed:     collections/src/test/org/apache/commons/collections/comparators
                        TestComparator.java
  Log:
  Rename TestComparator to AbstractTestComparator
  Tidy comparator test classes licenses/javadoc
  
  Revision  Changes    Path
  1.7       +24 -16    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestComparatorChain.java	31 Aug 2003 17:28:46 -0000	1.6
  +++ TestComparatorChain.java	1 Oct 2003 22:14:48 -0000	1.7
  @@ -1,6 +1,7 @@
  -/* 
  - * $Id$
  +/*
  + * $Header$
    * ====================================================================
  + *
    * The Apache Software License, Version 1.1
    *
    * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  @@ -18,21 +19,21 @@
    *    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 acknowledgement:
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowledgement:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgement may appear in the software itself,
    *    if and wherever such third-party acknowledgements 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.
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" 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"
  + *    nor may "Apache" appear in their names 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
  @@ -52,8 +53,8 @@
    * 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;
  @@ -64,7 +65,14 @@
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  -public class TestComparatorChain extends TestComparator {
  +/**
  + * Tests for ComparatorChain.
  + * 
  + * @version $Revision$ $Date$
  + * 
  + * @author Unknown
  + */
  +public class TestComparatorChain extends AbstractTestComparator {
   
       public TestComparatorChain(String testName) {
           super(testName);
  @@ -74,7 +82,7 @@
           return new TestSuite(TestComparatorChain.class);
       }
   
  -    public Comparator makeComparator() {
  +    protected Comparator makeComparator() {
           ComparatorChain chain = new ComparatorChain(new ColumnComparator(0));
           chain.addComparator(new ColumnComparator(1),true); // reverse the second column
           chain.addComparator(new ColumnComparator(2),false);
  @@ -151,7 +159,7 @@
           assertTrue(chain.compare(new Integer(4), new Integer(4)) == 0);            
       }
   
  -    public List getComparableObjectsOrdered() {
  +    protected List getComparableObjectsOrdered() {
           List list = new LinkedList();
           // this is the correct order assuming a
           // "0th forward, 1st reverse, 2nd forward" sort
  
  
  
  1.4       +19 -19    jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java
  
  Index: TestBooleanComparator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestBooleanComparator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestBooleanComparator.java	31 Aug 2003 17:28:46 -0000	1.3
  +++ TestBooleanComparator.java	1 Oct 2003 22:14:48 -0000	1.4
  @@ -1,9 +1,10 @@
  -/* 
  +/*
    * $Header$
    * ====================================================================
  + *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -18,21 +19,21 @@
    *    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 acknowledgement:
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowledgement:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgement may appear in the software itself,
    *    if and wherever such third-party acknowledgements 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.
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" 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"
  + *    nor may "Apache" appear in their names 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
  @@ -52,6 +53,7 @@
    * 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;
   
  @@ -65,13 +67,11 @@
   /**
    * Tests for {@link BooleanComparator}.
    * 
  - * @since Commons Collections 2.2
  - * 
    * @version $Revision$ $Date$
    * 
    * @author Rodney Waldhoff
    */
  -public class TestBooleanComparator extends TestComparator {
  +public class TestBooleanComparator extends AbstractTestComparator {
   
       // conventional
       // ------------------------------------------------------------------------
  @@ -87,11 +87,11 @@
       // collections testing framework
       // ------------------------------------------------------------------------
   
  -    public Comparator makeComparator() {
  +    protected Comparator makeComparator() {
           return new BooleanComparator();
       }
   
  -    public List getComparableObjectsOrdered() {
  +    protected List getComparableObjectsOrdered() {
           List list = new ArrayList();
           list.add(new Boolean(false));
           list.add(Boolean.FALSE);
  
  
  
  1.6       +24 -16    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestReverseComparator.java	31 Aug 2003 17:28:46 -0000	1.5
  +++ TestReverseComparator.java	1 Oct 2003 22:14:48 -0000	1.6
  @@ -1,6 +1,7 @@
  -/* 
  - * $Id$
  +/*
  + * $Header$
    * ====================================================================
  + *
    * The Apache Software License, Version 1.1
    *
    * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  @@ -18,21 +19,21 @@
    *    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 acknowledgement:
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowledgement:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgement may appear in the software itself,
    *    if and wherever such third-party acknowledgements 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.
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" 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"
  + *    nor may "Apache" appear in their names 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
  @@ -52,8 +53,8 @@
    * 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;
  @@ -68,7 +69,14 @@
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  -public class TestReverseComparator extends TestComparator {
  +/**
  + * Tests for ReverseComparator.
  + * 
  + * @version $Revision$ $Date$
  + * 
  + * @author Unknown
  + */
  +public class TestReverseComparator extends AbstractTestComparator {
   
       public TestReverseComparator(String testName) {
           super(testName);
  @@ -88,11 +96,11 @@
        * 
        * @return Comparator that returns "natural" order
        */
  -    public Comparator makeComparator() {
  +    protected Comparator makeComparator() {
           return new ReverseComparator(Collections.reverseOrder());
       }
   
  -    public List getComparableObjectsOrdered() {
  +    protected List getComparableObjectsOrdered() {
           List list = new LinkedList();
           list.add(new Integer(1));
           list.add(new Integer(2));
  
  
  
  1.6       +26 -22    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestNullComparator.java	31 Aug 2003 17:28:46 -0000	1.5
  +++ TestNullComparator.java	1 Oct 2003 22:14:48 -0000	1.6
  @@ -1,9 +1,10 @@
  -package org.apache.commons.collections.comparators;
  -
  -/* ====================================================================
  +/*
  + * $Header$
  + * ====================================================================
  + *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -18,21 +19,21 @@
    *    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 acknowledgement:
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowledgement:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgement may appear in the software itself,
    *    if and wherever such third-party acknowledgements 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.
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" 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"
  + *    nor may "Apache" appear in their names 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
  @@ -52,7 +53,9 @@
    * 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.util.Comparator;
   import java.util.LinkedList;
  @@ -62,12 +65,13 @@
   import junit.framework.TestSuite;
   
   /**
  - *  Test the NullComparator 
  - *
  - *  @author <a href="mailto:mas@apache.org">Michael A. Smith</a>
  - *  @version $Id$
  - **/
  -public abstract class TestNullComparator extends TestComparator {
  + * Test the NullComparator.
  + * 
  + * @version $Revision$ $Date$
  + * 
  + * @author Michael A. Smith
  + */
  +public abstract class TestNullComparator extends AbstractTestComparator {
   
       public TestNullComparator(String testName) {
           super(testName);
  @@ -89,11 +93,11 @@
   	    super(testName);
   	}
   
  -	public Comparator makeComparator() {
  +    protected Comparator makeComparator() {
   	    return new NullComparator();
   	}
   	
  -	public List getComparableObjectsOrdered() {
  +    protected List getComparableObjectsOrdered() {
           List list = new LinkedList();
   	    list.add(new Integer(1));
   	    list.add(new Integer(2));
  
  
  
  1.4       +5 -6      jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java
  
  Index: TestFixedOrderComparator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestFixedOrderComparator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestFixedOrderComparator.java	31 Aug 2003 17:28:46 -0000	1.3
  +++ TestFixedOrderComparator.java	1 Oct 2003 22:14:48 -0000	1.4
  @@ -1,13 +1,10 @@
   /*
    * $Header$
  - * $Revision$
  - * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -36,7 +33,7 @@
    *
    * 5. Products derived from this software may not be called "Apache"
    *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  + *    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
  @@ -72,6 +69,8 @@
   
   /**
    * Test class for FixedOrderComparator.
  + * 
  + * @version $Revision$ $Date$
    * 
    * @author David Leppik 
    * @author Stephen Colebourne
  
  
  
  1.3       +67 -3     jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java
  
  Index: TestComparableComparator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparableComparator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestComparableComparator.java	12 Oct 2002 22:36:23 -0000	1.2
  +++ TestComparableComparator.java	1 Oct 2003 22:14:48 -0000	1.3
  @@ -1,3 +1,60 @@
  +/*
  + * $Header$
  + * ====================================================================
  + *
  + * 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 acknowledgement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgement may appear in the software itself,
  + *    if and wherever such third-party acknowledgements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" 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"
  + *    nor may "Apache" appear in their names 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.util.Comparator;
  @@ -7,7 +64,14 @@
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  -public class TestComparableComparator extends TestComparator {
  +/**
  + * Tests for ComparableComparator.
  + * 
  + * @version $Revision$ $Date$
  + * 
  + * @author Unknown
  + */
  +public class TestComparableComparator extends AbstractTestComparator {
   
       public TestComparableComparator(String testName) {
           super(testName);
  @@ -17,11 +81,11 @@
           return new TestSuite(TestComparableComparator.class);
       }
   
  -    public Comparator makeComparator() {
  +    protected Comparator makeComparator() {
           return new ComparableComparator();
       }
   
  -    public List getComparableObjectsOrdered() {
  +    protected List getComparableObjectsOrdered() {
           List list = new LinkedList();
           list.add(new Integer(1));
           list.add(new Integer(2));
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java
  
  Index: AbstractTestComparator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java,v
1.1 2003/10/01 22:14:48 scolebourne Exp $
   * ====================================================================
   *
   * 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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" 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"
   *    nor may "Apache" appear in their names 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.FileNotFoundException;
  import java.io.IOException;
  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.TestObject;
  
  /**
   * Abstract test class for testing the Comparator interface.
   * <p>
   * Concrete subclasses declare the comparator to be tested.
   * They also declare certain aspects of the tests.
   * 
   * @author Stephen Colebourne
   */
  public abstract class AbstractTestComparator extends TestObject {
  
      /**
       * JUnit constructor.
       * 
       * @param testName  the test class name
       */
      public AbstractTestComparator(String testName) {
          super(testName);
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement this method to return the comparator to test.
       * 
       * @return the comparator to test
       */
      protected abstract Comparator makeComparator();
      
      /**
       * Implement this method to return a list of sorted objects.
       * 
       * @return sorted objects
       */
      protected abstract List getComparableObjectsOrdered();
  
      //-----------------------------------------------------------------------
      /**
       * Implements the abstract superclass method to return the comparator.
       * 
       * @return a full iterator
       */
      protected Object makeObject() {
          return makeComparator();
      }
  
      /**
       * Overrides superclass to block tests.
       */
      public boolean supportsEmptyCollections() {
          return false;
      }
  
      /**
       * Overrides superclass to block tests.
       */
      public boolean supportsFullCollections() {
          return false;
      }
  
      /**
       * Overrides superclass to set the compatability to version 2
       * as there were no Comparators in version 1.x.
       */
      protected String getCompatibilityVersion() {
          return "2";
      }
  
      //-----------------------------------------------------------------------
      /**
       * Reverse the list.
       */
      protected void reverseObjects(List list) {
          Collections.reverse(list);
      }
  
      /**
       * Randomize the list.
       */
      protected void randomizeObjects(List list) {
          Collections.shuffle(list);
      }
  
      /**
       * Sort the list.
       */
      protected void sortObjects(List list, Comparator comparator) {
          Collections.sort(list,comparator);
  
      }
  
      //-----------------------------------------------------------------------
      /**
       * Test sorting an empty list
       */
      public void testEmptyListSort() {
          List list = new LinkedList();
          sortObjects(list, makeComparator());
  
          List list2 = new LinkedList();
          
          assertTrue("Comparator cannot sort empty lists",
                     list2.equals(list));
      }
  
      /**
       * Test sorting a reversed list.
       */
      public void testReverseListSort() {
          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));
  
      }
  
      /**
       * Test sorting a random list.
       */
      public void testRandomListSort() {
          Comparator comparator = makeComparator();
  
          List randomList = getComparableObjectsOrdered();
          randomizeObjects(randomList);
          sortObjects(randomList,comparator);
  
          List orderedList = getComparableObjectsOrdered();
  
          /* debug 
          Iterator i = randomList.iterator();
          while (i.hasNext()) {
              System.out.println(i.next());
          }
          */
  
          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);
      }
  
      public String getCanonicalComparatorName(Object object) {
          StringBuffer retval = new StringBuffer();
          retval.append("data/test/");
          String colName = object.getClass().getName();
          colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
          retval.append(colName);
          retval.append(".version");
          retval.append(getCompatibilityVersion());
          retval.append(".obj");
          return retval.toString();
      }
  
      /**
       * Compare the current serialized form of the Comparator
       * against the canonical version in CVS.
       */
      public void testComparatorCompatibility() throws IOException, ClassNotFoundException
{
          if(!skipSerializedCanonicalTests()) {
              Comparator comparator = null;
      
              // test to make sure the canonical form has been preserved
              try {
                  comparator = (Comparator) readExternalFormFromDisk(getCanonicalComparatorName(makeComparator()));
          	} catch (FileNotFoundException exception) {
      
                  boolean autoCreateSerialized = false;
      
          	    if(autoCreateSerialized) {
      	          	comparator = makeComparator();
              		String fileName = getCanonicalComparatorName(comparator);
              		writeExternalFormToDisk((Serializable) comparator, fileName);
              		fail("Serialized form could not be found.  A serialized version " +
              		     "has now been written (and should be added to CVS): " + fileName);
                  } else {
                      fail("The Serialized form could be located to test serialization " +
                          "compatibility: " + exception.getMessage());
                  }
              }
      
              
              // make sure the canonical form produces the ordering we currently
              // expect
              List randomList = getComparableObjectsOrdered();
              reverseObjects(randomList);
              sortObjects(randomList,comparator);
      
              List orderedList = getComparableObjectsOrdered();
      
              assertTrue("Comparator did not reorder the List correctly",
                         orderedList.equals(randomList));
          }
      }
  
  }
  
  
  

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