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 TestComparator.java
Date Fri, 01 Mar 2002 19:42:42 GMT
morgand     02/03/01 11:42:42

  Modified:    collections/src/test/org/apache/commons/collections/comparators
                        TestComparator.java
  Log:
  added backward compatibility tests for Serialization
  
  Revision  Changes    Path
  1.2       +52 -0     jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparator.java
  
  Index: TestComparator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/comparators/TestComparator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestComparator.java	1 Mar 2002 18:36:21 -0000	1.1
  +++ TestComparator.java	1 Mar 2002 19:42:42 -0000	1.2
  @@ -1,5 +1,6 @@
   package org.apache.commons.collections.comparators;
   
  +import java.io.IOException;
   import java.io.Serializable;
   import java.util.Collections;
   import java.util.Comparator;
  @@ -22,6 +23,15 @@
           return makeComparator();
       }
   
  +    /**
  +     * There were no Comparators in version 1.x.
  +     * 
  +     * @return 2
  +     */
  +    public int getCompatibilityVersion() {
  +        return 2;
  +    }
  +
       public void reverseObjects(List list) {
           Collections.reverse(list);
       }
  @@ -77,6 +87,48 @@
           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
{
  +        Comparator comparator = null;
  +        /*
  +         * Create canonical objects with this code
  +        comparator = makeComparator();
  +        
  +        writeExternalFormToDisk((Serializable) comparator, 
  +                                getCanonicalComparatorName(comparator));
  +        */
  +
  +        // test to make sure the canonical form has been preserved
  +        comparator = 
  +            (Comparator) readExternalFormFromDisk(getCanonicalComparatorName(makeComparator()));
  +        
  +        // 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:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message