You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ma...@apache.org on 2002/02/22 03:18:51 UTC

cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestBeanMap.java TestDoubleOrderedMap.java TestFastHashMap1.java TestFastTreeMap.java TestFastTreeMap1.java TestHashMap.java TestLRUMap.java TestMap.java TestMultiHashMap.java TestObject.java TestSequencedHashMap.java TestTreeMap.java

mas         02/02/21 18:18:51

  Modified:    collections/src/test/org/apache/commons/collections
                        TestBeanMap.java TestDoubleOrderedMap.java
                        TestFastHashMap1.java TestFastTreeMap.java
                        TestFastTreeMap1.java TestHashMap.java
                        TestLRUMap.java TestMap.java TestMultiHashMap.java
                        TestObject.java TestSequencedHashMap.java
                        TestTreeMap.java
  Log:
  Added a bunch of generic tests to the TestMap.java class.  Also added
  cooresponding changes to other tests.  These tests expose a few deviations from
  the Map contract in BeanMap.  These should either be fixed, or BeanMap should be
  documented to describe how it differs from the Map contract.
  
  Revision  Changes    Path
  1.2       +183 -5    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestBeanMap.java	20 Feb 2002 23:33:23 -0000	1.1
  +++ TestBeanMap.java	22 Feb 2002 02:18:50 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBeanMap.java,v 1.1 2002/02/20 23:33:23 morgand Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/20 23:33:23 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBeanMap.java,v 1.2 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -79,8 +79,186 @@
           return new TestSuite(TestBeanMap.class);
       }
   
  -    public Map makeMap() {
  -        return new BeanMap();
  +/*
  +  note to self.  The getter and setter methods were generated by copying the
  +  field declarations and using the following regular expression search and
  +  replace:
  +
  +  From:
  +        private \(.*\) some\(.*\);
  +  To:
  +        public \1 getSome\2Value() {
  +            return some\2;
  +        }
  +        public void setSome\2Value(\1 value) {
  +            some\2 = value;
  +        } 
  +
  +  Also note:  The sample keys and mappings were generated manually.
  +*/
  +
  +
  +    public static class BeanWithProperties {
  +        private int someInt;
  +        private long someLong;
  +        private double someDouble;
  +        private float someFloat;
  +        private short someShort;
  +        private byte someByte;
  +        private char someChar;
  +        private Integer someInteger;
  +        private String someString;
  +        private Object someObject;
  +
  +        public int getSomeIntValue() {
  +            return someInt;
  +        }
  +        public void setSomeIntValue(int value) {
  +            someInt = value;
  +        }
  +
  +        public long getSomeLongValue() {
  +            return someLong;
  +        }
  +        public void setSomeLongValue(long value) {
  +            someLong = value;
  +        }
  +
  +        public double getSomeDoubleValue() {
  +            return someDouble;
  +        }
  +        public void setSomeDoubleValue(double value) {
  +            someDouble = value;
  +        }
  +
  +        public float getSomeFloatValue() {
  +            return someFloat;
  +        }
  +        public void setSomeFloatValue(float value) {
  +            someFloat = value;
  +        }
  +
  +        public short getSomeShortValue() {
  +            return someShort;
  +        }
  +        public void setSomeShortValue(short value) {
  +            someShort = value;
  +        }
  +
  +        public byte getSomeByteValue() {
  +            return someByte;
  +        }
  +        public void setSomeByteValue(byte value) {
  +            someByte = value;
  +        }
  +
  +        public char getSomeCharValue() {
  +            return someChar;
  +        }
  +        public void setSomeCharValue(char value) {
  +            someChar = value;
  +        }
  +
  +        public String getSomeStringValue() {
  +            return someString;
  +        }
  +        public void setSomeStringValue(String value) {
  +            someString = value;
  +        }
  +
  +        public Integer getSomeIntegerValue() {
  +            return someInteger;
  +        }
  +        public void setSomeIntegerValue(Integer value) {
  +            someInteger = value;
  +        }
  +
  +        public Object getSomeObjectValue() {
  +            return someObject;
  +        }
  +        public void setSomeObjectValue(Object value) {
  +            someObject = value;
  +        }
       }
   
  +
  +/*
  +  note to self.  The Sample keys were generated by copying the field
  +  declarations and using the following regular expression search and replace:
  +
  +  From:
  +        private \(.*\) some\(.*\);
  +  To:
  +            "some\2Value", 
  +
  +  Then, I manually added the "class" key, which is a property that exists for
  +  all beans (and all objects for that matter.
  +*/
  +
  +    public Object[] getSampleKeys() {
  +        Object[] keys = new Object[] {
  +            "someIntValue",
  +            "someLongValue",
  +            "someDoubleValue",
  +            "someFloatValue",
  +            "someShortValue",
  +            "someByteValue",
  +            "someCharValue",
  +            "someIntegerValue",
  +            "someStringValue",
  +            "someObjectValue",
  +            "class",
  +        };
  +        return keys;
  +    }
  +
  +/*
  +    note to self: the sample values were created manually
  +*/
  +
  +    public Object[] getSampleValues() {
  +        Object[] values = new Object[] {
  +            new Integer(1234),
  +            new Long(1298341928234L),
  +            new Double(123423.34),
  +            new Float(1213332.12f),
  +            new Short((short)134),
  +            new Byte((byte)10),
  +            new Character('a'),
  +            new Integer(1432),
  +            "SomeStringValue",
  +            new Object(),
  +            BeanWithProperties.class,
  +        };
  +        return values;
  +    }
  +
  +    public Object[] getNewSampleValues() {
  +        Object[] values = new Object[] {
  +            new Integer(223),
  +            new Long(23341928234L),
  +            new Double(23423.34),
  +            new Float(213332.12f),
  +            new Short((short)234),
  +            new Byte((byte)20),
  +            new Character('b'),
  +            new Integer(232),
  +            "SomeNewStringValue",
  +            new Object(),
  +            null,
  +        };
  +        return values;
  +    }
  +
  +    public boolean isAddRemoveModifiable() {
  +        return false;
  +    }
  +  
  +    public Map makeFullMap() {
  +        return new BeanMap(new BeanWithProperties());
  +    }
  +
  +    public Map makeEmptyMap() {
  +        return new BeanMap();
  +    }
   }
  
  
  
  1.3       +29 -3     jakarta-commons/collections/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java
  
  Index: TestDoubleOrderedMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestDoubleOrderedMap.java	20 Feb 2002 23:48:13 -0000	1.2
  +++ TestDoubleOrderedMap.java	22 Feb 2002 02:18:50 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java,v 1.2 2002/02/20 23:48:13 morgand Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/20 23:48:13 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java,v 1.3 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -96,6 +96,32 @@
        */
       public static Test suite() {
           return new TestSuite(TestDoubleOrderedMap.class);
  +    }
  +
  +    /**
  +     *  The default comparator in double ordered map does not allow null keys.
  +     **/
  +    public boolean useNullKey() {
  +        return false;
  +    }
  +
  +    /**
  +     *  The default comparator in double ordered map does not allow null keys,
  +     *  and values are keys in this map.
  +     **/
  +    public boolean useNullValue() {
  +        return false;
  +    }
  +
  +    /**
  +     *  Double ordered map does not support duplicate values
  +     **/
  +    public boolean useDuplicateValues() {
  +        return false;
  +    }
  +
  +    public Map makeEmptyMap() {
  +        return new DoubleOrderedMap();
       }
   
       public Map makeMap() {
  
  
  
  1.2       +34 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastHashMap1.java
  
  Index: TestFastHashMap1.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastHashMap1.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestFastHashMap1.java	21 Apr 2001 12:22:30 -0000	1.1
  +++ TestFastHashMap1.java	22 Feb 2002 02:18:50 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastHashMap1.java,v 1.1 2001/04/21 12:22:30 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/04/21 12:22:30 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastHashMap1.java,v 1.2 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -71,7 +71,7 @@
    * Test FastHashMap in <strong>fast</strong> mode.
    *
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: TestFastHashMap1.java,v 1.1 2001/04/21 12:22:30 craigmcc Exp $
  + * @version $Id: TestFastHashMap1.java,v 1.2 2002/02/22 02:18:50 mas Exp $
    */
   public class TestFastHashMap1 extends TestFastHashMap
   {
  @@ -95,6 +95,36 @@
           FastHashMap fhm = new FastHashMap();
           fhm.setFast(true);
           return (fhm);
  +    }
  +
  +    /**
  +     *  When the fast hash map is in fast mode, the underlying hash map is
  +     *  cloned on modification (i.e. on a put).  Because of that, any
  +     *  previously existing entry set will be representing the old (pre-clone)
  +     *  map and will not reflect changes made to the map after the clone.  So,
  +     *  we must override this test.
  +     **/
  +    public void testEntrySetChangesWithMapPut() {
  +    }
  +
  +    /**
  +     *  When the fast hash map is in fast mode, the underlying hash map is
  +     *  cloned on modification (i.e. on a remove).  Because of that, any
  +     *  previously existing entry set will be representing the old (pre-clone)
  +     *  map and will not reflect changes made to the map after the clone.  So,
  +     *  we must override this test.
  +     **/
  +    public void testEntrySetChangesWithMapRemove() {
  +    }
  +
  +    /**
  +     *  When the fast hash map is in fast mode, the underlying hash map is
  +     *  cloned on modification (i.e. on a put).  Because of that, any
  +     *  previously existing entry set will be representing the old (pre-clone)
  +     *  map, so changes to the set will not be seen in the map. So, we must
  +     *  override this test.
  +     **/
  +    public void testEntrySetRemoveCausesMapModification() {
       }
   
       public void setUp()
  
  
  
  1.4       +11 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap.java
  
  Index: TestFastTreeMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestFastTreeMap.java	21 Apr 2001 12:22:30 -0000	1.3
  +++ TestFastTreeMap.java	22 Feb 2002 02:18:50 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap.java,v 1.3 2001/04/21 12:22:30 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/04/21 12:22:30 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap.java,v 1.4 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -69,7 +69,7 @@
   
   /**
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: TestFastTreeMap.java,v 1.3 2001/04/21 12:22:30 craigmcc Exp $
  + * @version $Id: TestFastTreeMap.java,v 1.4 2002/02/22 02:18:50 mas Exp $
    */
   public class TestFastTreeMap extends TestTreeMap
   {
  @@ -93,6 +93,13 @@
           FastTreeMap ftm = new FastTreeMap();
           ftm.setFast(false);
           return (ftm);
  +    }
  +  
  +    /**
  +     *  The comparator for the fast tree map does not support null keys.
  +     **/
  +    public boolean useNullKey() {
  +      return false;
       }
   
       public void setUp()
  
  
  
  1.2       +33 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap1.java
  
  Index: TestFastTreeMap1.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap1.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestFastTreeMap1.java	21 Apr 2001 12:22:30 -0000	1.1
  +++ TestFastTreeMap1.java	22 Feb 2002 02:18:50 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap1.java,v 1.1 2001/04/21 12:22:30 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/04/21 12:22:30 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFastTreeMap1.java,v 1.2 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -71,7 +71,7 @@
    * Test FastTreeMap in <strong>fast</strong> mode.
    *
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: TestFastTreeMap1.java,v 1.1 2001/04/21 12:22:30 craigmcc Exp $
  + * @version $Id: TestFastTreeMap1.java,v 1.2 2002/02/22 02:18:50 mas Exp $
    */
   public class TestFastTreeMap1 extends TestFastTreeMap
   {
  @@ -102,4 +102,33 @@
           map = (TreeMap) makeMap();
       }
   
  +    /**
  +     *  When the fast tree map is in fast mode, the underlying tree map is
  +     *  cloned on modification (i.e. on a put).  Because of that, any
  +     *  previously existing entry set will be representing the old (pre-clone)
  +     *  map and will not reflect changes made to the map after the clone.  So,
  +     *  we must override this test.
  +     **/
  +    public void testMapEntrySetChangesWithMapPut() {
  +    }
  +
  +    /**
  +     *  When the fast tree map is in fast mode, the underlying tree map is
  +     *  cloned on modification (i.e. on a put).  Because of that, any
  +     *  previously existing entry set will be representing the old (pre-clone)
  +     *  map and will not reflect changes made to the map after the clone.  So,
  +     *  we must override this test.
  +     **/
  +    public void testMapEntrySetChangesWithMapRemove() {
  +    }
  +
  +    /**
  +     *  When the fast tree map is in fast mode, the underlying tree map is
  +     *  cloned on modification (i.e. on a put).  Because of that, any
  +     *  previously existing entry set will be representing the old (pre-clone)
  +     *  map, so changes to the set will not be seen in the map. So, we must
  +     *  override this test.
  +     **/
  +    public void testMapEntrySetRemoveCausesMapModification() {
  +    }
   }
  
  
  
  1.3       +6 -6      jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java
  
  Index: TestHashMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestHashMap.java	14 Jul 2001 23:33:27 -0000	1.2
  +++ TestHashMap.java	22 Feb 2002 02:18:50 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/07/14 23:33:27 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java,v 1.3 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -69,7 +69,7 @@
   
   /**
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: TestHashMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
  + * @version $Id: TestHashMap.java,v 1.3 2002/02/22 02:18:50 mas Exp $
    */
   public class TestHashMap extends TestMap
   {
  @@ -89,7 +89,7 @@
           junit.textui.TestRunner.main(testCaseName);
       }
   
  -    public Map makeMap() {
  +    public Map makeEmptyMap() {
           HashMap hm = new HashMap();
           return (hm);
       }
  @@ -98,7 +98,7 @@
   
       public void setUp()
       {
  -        map = (HashMap) makeMap();
  +        map = (HashMap) makeEmptyMap();
       }
   
       public void testNewMap()
  
  
  
  1.15      +18 -6     jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java
  
  Index: TestLRUMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TestLRUMap.java	20 Feb 2002 22:38:46 -0000	1.14
  +++ TestLRUMap.java	22 Feb 2002 02:18:50 -0000	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.14 2002/02/20 22:38:46 morgand Exp $
  - * $Revision: 1.14 $
  - * $Date: 2002/02/20 22:38:46 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.15 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.15 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -77,7 +77,7 @@
    * 
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @author <a href="mailto:morgand@apache.org">Morgan Delagrange</a>
  - * @version $Id: TestLRUMap.java,v 1.14 2002/02/20 22:38:46 morgand Exp $
  + * @version $Id: TestLRUMap.java,v 1.15 2002/02/22 02:18:50 mas Exp $
    */
   public class TestLRUMap extends TestSequencedHashMap
   {
  @@ -104,9 +104,21 @@
           map2.put(new Integer(1),"foo");
           map2.put(new Integer(2),"foo");
           map2.put(new Integer(3),"foo");
  -        map2.put(new Integer(4),"foo");
  +        map2.put(new Integer(4),"foo"); // removes 1 since max size exceeded
  +        map2.removeLRU();  // should be Integer(2)
   
  -        assertTrue("last value should exist",map2.get(new Integer(4)).equals("foo"));
  +        assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo"));
  +        assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null);
  +    }
  +
  +    public void testMultiplePuts() {
  +        LRUMap map2 = new LRUMap(2);
  +        map2.put(new Integer(1),"foo");
  +        map2.put(new Integer(2),"bar");
  +        map2.put(new Integer(3),"foo");
  +        map2.put(new Integer(4),"bar");
  +
  +        assertTrue("last value should exist",map2.get(new Integer(4)).equals("bar"));
           assertTrue("LRU should not exist", map2.get(new Integer(1)) == null);
       }
   
  
  
  
  1.8       +696 -56   jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java
  
  Index: TestMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestMap.java	21 Feb 2002 20:14:37 -0000	1.7
  +++ TestMap.java	22 Feb 2002 02:18:50 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java,v 1.7 2002/02/21 20:14:37 morgand Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/02/21 20:14:37 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java,v 1.8 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -64,20 +64,28 @@
   import junit.framework.*;
   import java.util.Collection;
   import java.util.Map;
  +import java.util.Collection;
   import java.util.Set;
  +import java.util.Iterator;
  +import java.util.HashSet;
  +import java.util.NoSuchElementException;
   
   /**
    * Tests base {@link java.util.Map} methods and contracts.
    * <p>
  - * To use, simply extend this class, and implement
  - * the {@link #makeMap} method.
  + * If your class implements the full Map interface, including optional
  + * operations, simply extend this class, and implement the {@link
  + * #makeEmptyMap()} method.
    * <p>
  - * If your {@link Map} fails one of these tests by design,
  - * you may still use this base set of cases.  Simply override the
  - * test case (method) your {@link Map} fails.
  + * If your {@link Map} fails one of these tests by design, you may still use
  + * this base set of cases.  Simply override the test case (method) your {@link
  + * Map} fails and/or the methods that define the assumptions used by the test
  + * cases.  For example, if your map does not allow duplicate values, override
  + * {@link useDuplicateValues()} and have it return <code>false</code>
    *
  + * @author Michael Smith
    * @author Rodney Waldhoff
  - * @version $Id: TestMap.java,v 1.7 2002/02/21 20:14:37 morgand Exp $
  + * @version $Id: TestMap.java,v 1.8 2002/02/22 02:18:50 mas Exp $
    */
   public abstract class TestMap extends TestObject {
       public TestMap(String testName) {
  @@ -85,53 +93,697 @@
       }
   
       /**
  -     * Return a new, empty {@link Map} to used for testing.
  +     *  Override if your map does not allow a <code>null</code> key.  The
  +     *  default implementation returns <code>true</code>
  +     **/
  +    public boolean useNullKey() {
  +        return true;
  +    }
  +
  +    /**
  +     *  Override if your map does not allow <code>null</code> values.  The
  +     *  default implementation returns <code>true</code>.
  +     **/
  +    public boolean useNullValue() {
  +        return true;
  +    }
  +
  +    /**
  +     *  Override if your map does not allow duplicate values.  The default
  +     *  implementation returns <code>true</code>.
  +     **/
  +    public boolean useDuplicateValues() {
  +        return true;
  +    }
  +
  +    /**
  +     *  Override if your map allows its mappings to be changed to new values.
  +     *  The default implementation returns <code>true</code>.
  +     **/
  +    public boolean isChangeable() {
  +        return true;
  +    }
  +
  +    /**
  +     *  Override if your map does not allow add/remove modifications.  The
  +     *  default implementation returns <code>true</code>.
  +     **/
  +    public boolean isAddRemoveModifiable() {
  +        return true;
  +    }
  +
  +    /**
  +     *  Returns the set of keys in the mappings used to test the map.  This
  +     *  method must return an array with the same length as {@link
  +     *  #getSampleValues()} and all array elements must be different. The
  +     *  default implementation constructs a set of String keys, and includes a
  +     *  single null key if {@link #useNullKey()} returns <code>true</code>.
  +     **/
  +    public Object[] getSampleKeys() {
  +        Object[] result = new Object[] {
  +            "blah", "foo", "bar", "baz", "tmp", "gosh", "golly", "gee", 
  +            "hello", "goodbye", "we'll", "see", "you", "all", "again",
  +            "key",
  +            "key2",
  +            (useNullKey()) ? null : "nonnullkey"
  +        };
  +        return result;
  +    }
  +
  +    /**
  +     *  Returns the set of values in the mappings used to test the map.  This
  +     *  method must return an array with the same length as {@link
  +     *  #getSampleKeys()}.  The default implementation contructs a set of
  +     *  String values and includes a single null value if {@link
  +     *  #useNullValue()} returns <code>true</code>, and includes two values
  +     *  that are the same if {@link #useDuplicateValues()} returns
  +     *  <code>true</code>.
  +     **/
  +    public Object[] getSampleValues() {
  +        Object[] result = new Object[] {
  +            "blahv", "foov", "barv", "bazv", "tmpv", "goshv", "gollyv", "geev",
  +            "hellov", "goodbyev", "we'llv", "seev", "youv", "allv", "againv",
  +            (useNullValue()) ? null : "nonnullvalue",
  +            "value",
  +            (useDuplicateValues()) ? "value" : "value2",
  +        };
  +        return result;
  +    }
  +
  +    /**
  +     *  Returns a the set of values that can be used to replace the values
  +     *  returned from {@link #getSampleValues()}.  This method must return an
  +     *  array with the same length as {@link #getSampleValues()}.  The values
  +     *  returned from this method should not be the same as those returned from
  +     *  {@link #getSampleValues()}.  The default implementation constructs a
  +     *  set of String values and includes a single null value if {@link
  +     *  #useNullValue()} returns <code>true</code>, and includes two values
  +     *  that are the same if {@link #useDuplicateValues()} returns
  +     *  <code>true</code>.  
  +     **/
  +    public Object[] getNewSampleValues() {
  +        Object[] result = new Object[] {
  +            (useNullValue()) ? null : "newnonnullvalue",
  +            "newvalue",
  +            (useDuplicateValues()) ? "newvalue" : "newvalue2",
  +            "newblahv", "newfoov", "newbarv", "newbazv", "newtmpv", "newgoshv", 
  +            "newgollyv", "newgeev", "newhellov", "newgoodbyev", "newwe'llv", 
  +            "newseev", "newyouv", "newallv", "newagainv",
  +        };
  +        return result;
  +    }
  +
  +    /**
  +     *  Helper method to add all the mappings described by {@link
  +     *  #getSampleKeys()} and {@link #getSampleValues()}.
  +     **/
  +    public void addSampleMappings(Map m) {
  +
  +        Object[] keys = getSampleKeys();
  +        Object[] values = getSampleValues();
  +        
  +        for(int i = 0; i < keys.length; i++) {
  +            try {
  +                m.put(keys[i], values[i]);
  +            } catch (NullPointerException exception) {
  +                assertTrue("NullPointerException only allowed to be thrown " +
  +                           "if either the key or value is null.", 
  +                           keys[i] == null || values[i] == null);
  +                
  +                assertTrue("NullPointerException on null key, but " +
  +                           "useNullKey is not overridden to return false.", 
  +                           keys[i] == null || !useNullKey());
  +                
  +                assertTrue("NullPointerException on null value, but " +
  +                           "useNullValue is not overridden to return false.",
  +                           values[i] == null || !useNullValue());
  +                
  +                assertTrue("Unknown reason for NullPointer.", false);
  +            }
  +        }
  +        assertEquals("size must reflect number of mappings added.",
  +                     keys.length, m.size());
  +    }
  +
  +    /**
  +     * Return a new, empty {@link Map} to be used for testing. 
        */
  -    public abstract Map makeMap();
  +    public abstract Map makeEmptyMap();
  +
  +    /**
  +     *  Return a new, populated map.  The mappings in the map should match the
  +     *  keys and values returned from {@linke #getSampleKeys()} and {@link
  +     *  #getSampleValues()}.  The default implementation uses makeEmptyMap()
  +     *  and calls {@link #addSampleMappings()} to add all the mappings to the
  +     *  map.
  +     **/
  +    public Map makeFullMap() {
  +        Map m = makeEmptyMap();
  +        addSampleMappings(m);
  +        return m;
  +    }
   
       public Object makeObject() {
  -        return makeMap();
  +        return makeEmptyMap();
       }
   
  -        /**
  -     * Try to put the given pair into the given Collection.
  +    /**
  +     *  Test to ensure the test setup is working properly.  This method checks
  +     *  to ensure that the getSampleKeys and getSampleValues methods are
  +     *  returning results that look appropriate.  That is, they both return a
  +     *  non-null array of equal length.  The keys array must not have any
  +     *  duplicate values, and may only contain a (single) null key if
  +     *  useNullKey() returns true.  The values array must only have a null
  +     *  value if useNullValue() is true and may only have duplicate values if
  +     *  useDuplicateValues() returns true.  
  +     **/
  +    public void testSampleMappings() {
  +      Object[] keys = getSampleKeys();
  +      Object[] values = getSampleValues();
  +      Object[] newValues = getNewSampleValues();
  +
  +      assertTrue("failure in test: Must have keys returned from " +
  +                 "getSampleKeys.", keys != null);
  +
  +      assertTrue("failure in test: Must have values returned from " +
  +                 "getSampleValues.", values != null);
  +
  +      // verify keys and values have equivalent lengths (in case getSampleX are
  +      // overridden)
  +      assertEquals("failure in test: not the same number of sample " +
  +                   "keys and values.",  keys.length, values.length);
  +      
  +      assertEquals("failure in test: not the same number of values and new values.",
  +                   values.length, newValues.length);
  +
  +      // verify there aren't duplicate keys, and check values
  +      for(int i = 0; i < keys.length - 1; i++) {
  +          for(int j = i + 1; j < keys.length; j++) {
  +              assertTrue("failure in test: duplicate null keys.",
  +                         (keys[i] != null || keys[j] != null));
  +              assertTrue("failure in test: duplicate non-null key.",
  +                         (keys[i] == null || keys[j] == null || 
  +                          (!keys[i].equals(keys[j]) && 
  +                           !keys[j].equals(keys[i]))));
  +          }
  +          assertTrue("failure in test: found null key, but useNullKey " +
  +                     "is false.", keys[i] != null || useNullKey());
  +          assertTrue("failure in test: found null value, but useNullValue " +
  +                     "is false.", values[i] != null || useNullValue());
  +          assertTrue("failure in test: found null new value, but useNullValue " +
  +                     "is false.", newValues[i] != null || useNullValue());
  +          assertTrue("failure in test: values should not be the same as new value",
  +                     values[i] != newValues[i] && 
  +                     (values[i] == null || !values[i].equals(newValues[i])));
  +      }
  +    }
  +    
  +    // tests begin here.  Each test adds a little bit of tested functionality.
  +    // Many methods assume previous methods passed.  That is, they do not
  +    // exhaustively recheck things that have already been checked in a previous
  +    // test methods.  
  +
  +    /**
  +     *  Test to ensure that makeEmptyMap and makeFull returns a new non-null
  +     *  map with each invocation.  
  +     **/
  +    public void testMakeMap() {
  +        Map em = makeEmptyMap();
  +        assertTrue("failure in test: makeEmptyMap must return a non-null map.",
  +                   em != null);
  +        
  +        Map em2 = makeEmptyMap();
  +        assertTrue("failure in test: makeEmptyMap must return a non-null map.",
  +                   em != null);
  +
  +        assertTrue("failure in test: makeEmptyMap must return a new map " +
  +                   "with each invocation.", em != em2);
  +
  +        Map fm = makeFullMap();
  +        assertTrue("failure in test: makeFullMap must return a non-null map.",
  +                   fm != null);
  +        
  +        Map fm2 = makeFullMap();
  +        assertTrue("failure in test: makeFullMap must return a non-null map.",
  +                   fm != null);
  +
  +        assertTrue("failure in test: makeFullMap must return a new map " +
  +                   "with each invocation.", fm != fm2);
  +    }
  +
  +    /**
  +     *  Tests Map.isEmpty()
  +     **/
  +    public void testIsEmpty() {
  +        Map em = makeEmptyMap();
  +        assertEquals("Map.isEmpty() should return true with an empty map", 
  +                     true, em.isEmpty());
  +
  +        Map fm = makeFullMap();
  +        assertEquals("Map.isEmpty() should return false with a non-empty map",
  +                     false, fm.isEmpty());
  +    }
  +
  +    /**
  +     *  Tests Map.size()
  +     **/
  +    public void testSize() {
  +        Map em = makeEmptyMap();
  +        assertEquals("Map.size() should be 0 with an empty map",
  +                     0, em.size());
  +
  +        Map fm = makeFullMap();
  +        assertEquals("Map.size() should equal the number of entries in the map",
  +                     getSampleKeys().length, fm.size());
  +    }
  +
  +    /**
  +     *  Tests {@link Map#clear()}.  If the map {@link #isAddRemoveModifiable()
  +     *  can add and remove elements}, then {@link Map#size()} and {@link
  +     *  Map#isEmpty()} are used to ensure that map has no elements after a call
  +     *  to clear.  If the map does not support adding and removing elements,
  +     *  this method checks to ensure clear throws an
  +     *  UnsupportedOperationException.  This method checks that the both maps
  +     *  returned by makeEmptyMap and makeFullMap have correct behavior.
  +     **/
  +    public void testClear() {
  +        Map em = makeEmptyMap();
  +        try {
  +            em.clear();
  +            assertTrue("Map must throw UnsupportedOperationException if the " +
  +                       "map does not support removing elements", 
  +                       isAddRemoveModifiable());
  +            assertEquals("size() must return zero after clear.", 
  +                         0, em.size());
  +            assertEquals("isEmpty() must return true after clear.", 
  +                         true, em.isEmpty());
  +        } catch (UnsupportedOperationException exception) {
  +            assertTrue("Map must not throw UnsupportedOperationException if the " +
  +                       "map supports removing elements", !isAddRemoveModifiable());
  +        }
  +
  +        Map fm = makeFullMap();
  +        try {
  +            fm.clear();
  +            assertTrue("Map must throw UnsupportedOperationException if the " +
  +                       "map does not support removing elements", 
  +                       isAddRemoveModifiable());
  +            assertEquals("size() must return zero after clear.", 
  +                         0, fm.size());
  +            assertEquals("isEmpty() must return true after clear.", 
  +                         true, fm.isEmpty());
  +        } catch (UnsupportedOperationException exception) {
  +            assertTrue("Map must not throw UnsupportedOperationException if the " +
  +                       "map supports removing elements", !isAddRemoveModifiable());
  +        }
  +    }
  +
  +    /**
  +     *  Tests:
  +     *  <ul>
  +     *  <li> Map.entrySet().isEmpty()
  +     *  <li> Map.entrySet().size()
  +     *  </ul>
  +     **/
  +    public void testEntrySetIsEmpty() {
  +        Map em = makeEmptyMap();
  +        Set es = em.entrySet();
  +        
  +        assertEquals("entrySet() must return an empty set when map is empty.", 
  +                     em.isEmpty(), es.isEmpty());
  +        assertEquals("entrySet() must return a set with the same size as " +
  +                     "the map.", em.size(), es.size());
  +
  +        Map fm = makeEmptyMap();
  +        Set fs = fm.entrySet();
  +        
  +        assertEquals("entrySet() must return a non-empty set when map is not empty.", 
  +                     fm.isEmpty(), fs.isEmpty());
  +        assertEquals("entrySet() must return a set with the same size as " +
  +                     "the map.", fm.size(), fs.size());
  +    }
  +
  +    /**
  +     *  Tests Map.containsKey(Object) by verifying it returns false for all
  +     *  sample keys on a map created using makeEmptyMap() and returns true for
  +     *  all sample keys returned on a map created using makeFullMap()
  +     **/
  +    public void testContainsKey() {
  +        Object[] keys = getSampleKeys();
  +
  +        Map em = makeEmptyMap();
  +
  +        for(int i = 0; i < keys.length; i++) {
  +            assertTrue("Map must not contain key when map is empty", 
  +                       !em.containsKey(keys[i]));
  +        }
  +
  +        Map fm = makeFullMap();
  +
  +        for(int i = 0; i < keys.length; i++) {
  +            assertTrue("Map must contain key for a mapping in the map.", 
  +                       fm.containsKey(keys[i]));
  +        }
  +    }
  +
  +    /**
  +     *  Tests Map.containsValue(Object) by verifying it returns false for all
  +     *  sample alues on a map created using makeEmptyMap() and returns true for
  +     *  all sample values returned on a map created using makeFullMap.
  +     **/
  +    public void testContainsValue() {
  +        Object[] values = getSampleValues();
  +
  +        Map em = makeEmptyMap();
  +
  +        for(int i = 0; i < values.length; i++) {
  +            assertTrue("Empty map must not contain value", 
  +                       !em.containsValue(values[i]));
  +        }
  +
  +        Map fm = makeFullMap();
  +
  +        for(int i = 0; i < values.length; i++) {
  +            assertTrue("Map must contain value for a mapping in the map.", 
  +                       fm.containsValue(values[i]));
  +        }
  +    }
  +
  +    /**
  +     *  Test to ensure that Map.entrySet() returns a non-null set.
  +     **/
  +    public void testEntrySet() {
  +        Map em = makeEmptyMap();
  +        Set es = em.entrySet();
  +        
  +        assertTrue("entrySet() must return a non-null set.", es != null);
  +
  +        Map fm = makeEmptyMap();
  +        Set fs = fm.entrySet();
  +        
  +        assertTrue("entrySet() must return a non-null set.", fs != null);
  +    }
  +    
  +    /**
  +     *  Tests:
  +     *  <ul>
  +     *  <li> Map.entrySet().contains(Object)
  +     *  <li> Map.entrySet().containsAll(Collection)
  +     *  </ul>
        *
  -     * Fails any Throwable except UnsupportedOperationException,
  -     * ClassCastException, or IllegalArgumentException
  -     * or NullPointerException is thrown.
  -     */
  -    protected Object tryToPut(Map map, Object key, Object val) {
  +     *  Note:  This test relies on a working commons.collections.DefaultMapEntry class.
  +     **/
  +    public void testEntrySetContainsProperMappings() {
  +        Object[] keys = getSampleKeys();
  +        Object[] values = getSampleValues();
  +        Map.Entry[] entries = new Map.Entry[keys.length];
  +        HashSet mappings = new HashSet();
  +
  +        for(int i = 0; i < keys.length; i++) {
  +            entries[i] = new DefaultMapEntry(keys[i], values[i]);
  +            mappings.add(entries[i]);
  +        }
  +
  +        // test an empty map
  +        Map em = makeEmptyMap();
  +        Set es = em.entrySet();
  +
  +        for(int i = 0; i < keys.length; i++) {
  +            assertEquals("entrySet().contains(Object) must return false when map " +
  +                         "is empty", false, es.contains(entries[i]));
  +        }
  +
  +        assertEquals("entrySet().containsAll(Collection) must return false when the " +
  +                     "map is empty", false, es.containsAll(mappings));
  +
  +
  +        Map fm = makeFullMap();
  +        Set fs = fm.entrySet();
  +
  +        for(int i = 0; i < keys.length; i++) {
  +            assertEquals("entrySet().contains(Object) must return true when map " +
  +                         "contains the mapping", true, fs.contains(entries[i]));
  +        }
  +        assertEquals("entrySet().containsAll(Collection) must return true when the " +
  +                     "map contains the mapping", true, fs.containsAll(mappings));
  +
           try {
  -            return map.put(key,val);
  -        } catch(UnsupportedOperationException e) {
  -            return null;
  -        } catch(ClassCastException e) {
  -            return null;
  -        } catch(IllegalArgumentException e) {
  -            return null;
  -        } catch(NullPointerException e) {
  -            return null;
  -        } catch(Throwable t) {
  -            t.printStackTrace();
  -            fail("Map.put should only throw UnsupportedOperationException, ClassCastException, IllegalArgumentException or NullPointerException. Found " + t.toString());
  -            return null; // never get here, since fail throws exception
  +            es.containsAll((Collection)null);
  +            fail("entrySet().containsAll(null) should " +
  +                 "throw a NullPointerException");
  +        } catch (NullPointerException exception) {
  +            // expected
  +        }
  +        try {
  +            fs.containsAll((Collection)null);
  +            fail("entrySet().containsAll(null) should " +
  +                 "throw a NullPointerException");
  +        } catch (NullPointerException exception) {
  +            // expected
           }
       }
   
  -    /*
  +    // TODO: test entrySet().clear()
  +    // TODO: test entrySet().add() throws OperationNotSupported
  +    // TODO: test entrySet().addAll() throws OperationNotSupported
  +    // TODO: test entrySet().contains(Object)
  +    // TODO: test entrySet().containsAll(Collection)
  +    // TODO: test entrySet().equals(Object)
  +    // TODO: test entrySet().hashCode()
  +    // TODO: test entrySet().toArray()
  +    // TODO: test entrySet().toArray(Object[] a)
  +    // TODO: test entrySet().remove(Object)
  +    // TODO: test entrySet().removeAll(Collection)
  +    // TODO: test entrySet().retainAll(Collection)
   
  -    public void testMapContainsKey() {
  -        // XXX finish me
  +    /**
  +     *  Tests:
  +     *  <ul>
  +     *  <li> Map.entrySet().iterator()
  +     *  <li> Map.entrySet().iterator().hasNext()
  +     *  <li> Map.entrySet().iterator().next()
  +     *  </ul>
  +     **/
  +    public void testEntrySetIterator() {
  +        Map em = makeEmptyMap();
  +        Set es = em.entrySet();
  +        Iterator eiter = es.iterator();
  +
  +        assertEquals("entrySet().iterator().hasNext() must return false " +
  +                     "when then the map is empty.", 
  +                     false, eiter.hasNext());
  +
  +        // note: we make a new map to test for this because some impls in the
  +        // past have required a call to hasMoreElements before a call to next
  +        // for it to work properly.  By using a new map, we make sure this test
  +        // will catch those broken impls.
  +        em = makeEmptyMap();
  +        es = em.entrySet();
  +        eiter = es.iterator();
  +        
  +        try {
  +            eiter.next();
  +            fail("entrySet().iterator().next() must throw a NoSuchElementException " +
  +                 "when the map is empty");
  +        } catch (NoSuchElementException exception) {
  +            // expected
  +        }
  +
  +
  +        Map fm = makeFullMap();
  +
  +        Set fs = fm.entrySet();
  +
  +        Object[] keys = getSampleKeys();
  +        Object[] values = getSampleValues();
  +        boolean[] found = new boolean[keys.length];
  +
  +        Iterator iter = fs.iterator();
  +
  +        assertTrue("entrySet().iterator() must return a non-null " +
  +                   "iterator.", iter != null);
  +
  +        while(iter.hasNext()) {
  +            Object obj = iter.next();
  +            assertTrue("Null is not allowed to be returned from the " +
  +                       "entrySet().iterator()'s next().", obj != null);
  +            assertTrue("Objects returned from entrySet().iterator() must be " +
  +                       "instances of Map.Entry.", obj instanceof Map.Entry);
  +                
  +            Map.Entry entry = (Map.Entry)obj;
  +            Object key = entry.getKey();
  +            Object value = entry.getValue();
  +
  +            assertTrue("the key for an entry returned from the entry " +
  +                       "set's iterator can only be null if useNullKey " +
  +                       "is true.",
  +                       key != null || (key == null && useNullKey()));
  +            
  +            assertTrue("the value for an entry returned from the entry " +
  +                       "set's iterator can only be null if useNullValue " +
  +                       "is true.",
  +                       value != null || (value == null && useNullValue()));
  +
  +            for(int i = 0; i < keys.length; i++) {
  +                if((key == null && keys[i] == null) ||
  +                   (key != null && key.equals(keys[i]))) {
  +                    assertTrue("entrySet().iterator() must not return " +
  +                               "multiple entries with the same key.", 
  +                               !found[i]);
  +                        
  +                    found[i] = true;
  +
  +                    assertTrue
  +                        ("value of entry returned from iterator " +
  +                         "must be the value for the added mapping.",
  +                         (value == null && values[i] == null) ||
  +                         (value != null && value.equals(values[i])));
  +                }
  +            }
  +        }
  +        for(int i = 0; i < found.length; i++) {
  +            assertTrue("must find all added elements through entrySet's " +
  +                       "iterator().", found[i]);
  +        }
       }
  +  
  +    /**
  +     *  Tests Map.entrySet().iterator().remove()
  +     **/
  +    public void testEntrySetIteratorRemove() {
  +        Map m = makeFullMap();
  +        Set s = m.entrySet();
  +        Iterator iter = s.iterator();
   
  -    public void testMapContainsValue() {
  -        // XXX finish me
  +        try {
  +            iter.remove();
  +            fail("Entry set iterator must not allow a call to remove " +
  +                 "before any calls to next");
  +        } catch (IllegalStateException exception) {
  +            // expected exception provided add/remove modifiable
  +            assertTrue("iterator should throw UnsupportedOperationException " +
  +                       "if remove is not allowed from the entrySet().iterator()",
  +                       isAddRemoveModifiable());
  +        } catch (UnsupportedOperationException exception) {
  +            assertTrue("iterator should not throw UnsupportedOperationException " +
  +                       "if the map supports adding and removing elements",
  +                       !isAddRemoveModifiable());
  +        }
  +
  +        while(iter.hasNext()) {
  +            Map.Entry entry = (Map.Entry)iter.next();
  +            
  +            assertTrue("Entry key from entry set iterator must exist in map",
  +                       m.containsKey(entry.getKey()));
  +            try {
  +                iter.remove();
  +                // note: we do not check that the mapping was actually removed
  +                // from the map because some classes do not have their
  +                // entrySet().iterator() backed by the map.  That test occurs
  +                // below in testEntrySetIteratorRemoveCausesMapModification
  +            } catch (UnsupportedOperationException exception) {
  +                assertTrue("iterator should not throw UnsupportedOperationException " +
  +                           "if the map supports adding and removing elements",
  +                           !isAddRemoveModifiable());
  +            }
  +
  +            try {
  +                iter.remove();
  +                fail("Entry set iterator must not allow two calls to " +
  +                     "remove without a call to next.");
  +            } catch (IllegalStateException exception) {
  +                // expected exception provided add/remove modifiable
  +                assertTrue("iterator should throw UnsupportedOperationException " +
  +                           "if remove is not allowed from the entrySet().iterator()",
  +                           isAddRemoveModifiable());
  +            } catch (UnsupportedOperationException exception) {
  +                assertTrue("iterator should not throw UnsupportedOperationException " +
  +                           "if the map supports adding and removing elements",
  +                           !isAddRemoveModifiable());
  +            }
  +        }
       }
   
  -    public void testMapEntrySet() {
  -        // XXX finish me
  +    /**
  +     *  Tests whether the map's entrySet() is backed by the map by making sure
  +     *  a put in the map is reflected in the entrySet.  This test does nothing
  +     *  if add/remove modifications are not supported.
  +     **/
  +    public void testEntrySetChangesWithMapPut() {
  +        if(!isAddRemoveModifiable()) return;
  +
  +        Map m = makeEmptyMap();
  +
  +        // test insert reflected in entry set
  +        Set s = m.entrySet();
  +        addSampleMappings(m);
  +        assertEquals("entrySet() must only be empty if map is empty.",
  +                     m.isEmpty(), s.isEmpty());
  +        assertEquals("entrySet() must adjust size when map changes.",
  +                     m.size(), s.size());
  +        // TODO: test set and map reflect the same contents
  +    }
  +
  +    /**
  +     *  Tests whether the map's entrySet() is backed by the map by making sure
  +     *  a remove from the map is reflected in the entrySet.  This test does nothing
  +     *  if add/remove modifications are not supported.
  +     **/
  +    public void testEntrySetChangesWithMapRemove() {
  +        if(!isAddRemoveModifiable()) return;
  +
  +        Map m = makeFullMap();
  +        Set s = m.entrySet();
  +
  +        Object[] keys = getSampleKeys();
  +        Object[] values = getSampleValues();
  +
  +        for(int i = 0; i < keys.length; i++) {
  +            m.remove(keys[i]);
  +            assertEquals("entrySet() must only be empty if map is empty.",
  +                         m.isEmpty(), s.isEmpty());
  +            assertEquals("entrySet() must adjust size when map changes.",
  +                         m.size(), s.size());
  +            //TODO: test set and map reflect the same contents
  +        }
       }
   
  +    // TODO: test entrySet() changes after Map.remove
  +    // TODO: test entrySet() changes after Map.clear
  +    // TODO: test entrySet() changes after Map.putAll
  +
  +    /**
  +     *  Tests whether the map's entrySet() is backed by the map by making sure
  +     *  a remove from the entrySet's iterator is reflected in the map. This
  +     *  test does nothing if add/remove modifications are not supported.
  +     **/
  +    public void testEntrySetIteratorRemoveCausesMapModification() {
  +        if(!isAddRemoveModifiable()) return;
  +        
  +        Map m = makeFullMap();
  +        Set s = m.entrySet();
  +        Iterator iter = s.iterator();
  +        
  +        while(iter.hasNext()) {
  +            Map.Entry entry = (Map.Entry)iter.next();
  +            
  +            try {
  +                iter.remove();
  +                assertTrue("Entry key from entry set iterator must " +
  +                           "no longer exist in map",
  +                           !m.containsKey(entry.getKey()));
  +            } catch (UnsupportedOperationException exception) {
  +                // isAddRemoveModifiable is true -- we've checked that above
  +                fail("iterator should not throw UnsupportedOperationException " +
  +                     "if the map supports adding and removing elements");
  +            }
  +        }
  +    }
  +
  +    // TODO: test map changes after entrySet().remove
  +    // TODO: test map changes after entrySet().removeAll
  +    // TODO: test map changes after entrySet().retainAll
  +
       public void testMapEquals() {
           // XXX finish me
       }
  @@ -144,16 +796,10 @@
           // XXX finish me
       }
   
  -    public void testMapIsEmpty() {
  -        // XXX finish me
  -    }
  -
       public void testMapKeySet() {
           // XXX finish me
       }
       
  -    */
  -    
       //-------TEST AGAINST OPTIONAL OPERATIONS, ENABLE IN TEST SUBCLASSES
   
       public void testMapSupportsNullValues() {
  @@ -162,7 +808,7 @@
               return;
           }
   
  -        Map map = makeMap();
  +        Map map = makeEmptyMap();
           map.put(new Integer(1),"foo");
           
           assertTrue("no null values in Map",map.containsValue(null) == false);
  @@ -179,7 +825,7 @@
               return;
           }
   
  -        Map map = makeMap();
  +        Map map = makeEmptyMap();
           map.put(new Integer(4),"foo");
           map.put(new Integer(4),"bar");
           map.put(new Integer(4),"foo");
  @@ -195,7 +841,7 @@
               return;
           }
   
  -        Map map = makeMap();
  +        Map map = makeEmptyMap();
           map.put(new Integer(1),"foo");
           map.put(new Integer(2),"foo");
           map.put(new Integer(3),"foo");
  @@ -211,7 +857,7 @@
               return;
           }
   
  -        Map map = makeMap();
  +        Map map = makeEmptyMap();
           map.put("1","1");
           map.put("2","2");
           map.put("3","3");
  @@ -235,7 +881,7 @@
               return;
           }
   
  -        Map map = makeMap();
  +        Map map = makeEmptyMap();
           map.put("1","1");
           map.put("2","2");
           map.put("3","3");
  @@ -278,15 +924,9 @@
           // XXX finish me
       }
   
  -    public void testMapSize() {
  -        // XXX finish me
  -    }
  -
       public void testMapValues() {
           // XXX finish me
       }
  -
  -    */
   
       /**
        * Marker interface, indicating that a TestMap subclass
  
  
  
  1.2       +18 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestMultiHashMap.java
  
  Index: TestMultiHashMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestMultiHashMap.java	18 Sep 2001 10:41:39 -0000	1.1
  +++ TestMultiHashMap.java	22 Feb 2002 02:18:50 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v 1.1 2001/09/18 10:41:39 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/09/18 10:41:39 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v 1.2 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -90,7 +90,7 @@
           junit.textui.TestRunner.main(testCaseName);
       }
   
  -    public Map makeMap() {
  +    public Map makeEmptyMap() {
           return new MultiHashMap();
       }
       
  @@ -223,4 +223,18 @@
           return len;
       }
       
  +
  +    public void testEntrySetIterator() {
  +    }
  +    public void testEntrySetContainsProperMappings() {
  +    }
  +    public void testEntrySetIteratorHasProperMappings() {
  +        // override and ignore test -- it will fail when verifying the iterator for
  +        // the set contains the right value -- we're not returning the value, we're
  +        // returning a collection.
  +        // TODO: re-implement this test to ensure the values of the iterator match
  +        // the proper collection rather than the value the superclass is checking
  +        // for.
  +        return;
  +    }
   }
  
  
  
  1.3       +6 -5      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestObject.java	20 Feb 2002 21:50:16 -0000	1.2
  +++ TestObject.java	22 Feb 2002 02:18:50 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestObject.java,v 1.2 2002/02/20 21:50:16 morgand Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/20 21:50:16 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestObject.java,v 1.3 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -83,14 +83,14 @@
    * Tests base {@link java.util.Object} methods and contracts.
    * <p>
    * To use, simply extend this class, and implement
  - * the {@link #makeObject} method.
  + * the {@link #makeObject()} method.
    * <p>
    * If your {@link Object} fails one of these tests by design,
    * you may still use this base set of cases.  Simply override the
    * test case (method) your {@link Object} fails.
    *
    * @author Rodney Waldhoff
  - * @version $Id: TestObject.java,v 1.2 2002/02/20 21:50:16 morgand Exp $
  + * @version $Id: TestObject.java,v 1.3 2002/02/22 02:18:50 mas Exp $
    */
   public abstract class TestObject extends TestCase {
       public TestObject(String testName) {
  @@ -120,6 +120,7 @@
           Object obj2 = makeObject();
           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));
           }
       }
   
  
  
  
  1.7       +4 -4      jakarta-commons/collections/src/test/org/apache/commons/collections/TestSequencedHashMap.java
  
  Index: TestSequencedHashMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestSequencedHashMap.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestSequencedHashMap.java	21 Feb 2002 19:57:33 -0000	1.6
  +++ TestSequencedHashMap.java	22 Feb 2002 02:18:50 -0000	1.7
  @@ -98,10 +98,10 @@
           super.setUp();
           // use makeMap and cast the result to a SeqHashMap
           // so that subclasses of SeqHashMap can share these tests
  -        labRat = (SequencedHashMap) makeMap();
  +        labRat = (SequencedHashMap) makeEmptyMap();
       }
   
  -    public Map makeMap() {
  +    public Map makeEmptyMap() {
           return new SequencedHashMap();
       }
   
  @@ -112,7 +112,7 @@
       protected Object[] getValues() {
           return new Object[] { "bar", "frob", new Object() };
       }
  -
  + 
       public void testSequenceMap() throws Throwable {
           Object[] keys = getKeys();
           int expectedSize = keys.length;
  @@ -180,4 +180,4 @@
       protected void tearDown() {
           labRat = null;
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.3       +10 -6     jakarta-commons/collections/src/test/org/apache/commons/collections/TestTreeMap.java
  
  Index: TestTreeMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestTreeMap.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestTreeMap.java	14 Jul 2001 23:33:27 -0000	1.2
  +++ TestTreeMap.java	22 Feb 2002 02:18:50 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestTreeMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/07/14 23:33:27 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestTreeMap.java,v 1.3 2002/02/22 02:18:50 mas Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/22 02:18:50 $
    *
    * ====================================================================
    *
  @@ -69,7 +69,7 @@
   
   /**
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: TestTreeMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
  + * @version $Id: TestTreeMap.java,v 1.3 2002/02/22 02:18:50 mas Exp $
    */
   public class TestTreeMap extends TestMap
   {
  @@ -89,16 +89,20 @@
           junit.textui.TestRunner.main(testCaseName);
       }
   
  -    public Map makeMap() {
  +    public Map makeEmptyMap() {
           TreeMap tm = new TreeMap();
           return (tm);
       }
   
  +    public boolean useNullKey() {
  +      return false;
  +    }
  +
       protected TreeMap map = null;
   
       public void setUp()
       {
  -        map = (TreeMap) makeMap();
  +        map = (TreeMap) makeEmptyMap();
       }
   
       public void testNewMap()
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>