diff --git a/src/test/org/apache/commons/collections/AbstractTestMap.java b/src/test/org/apache/commons/collections/AbstractTestMap.java index 282e162bb..20ef4317a 100644 --- a/src/test/org/apache/commons/collections/AbstractTestMap.java +++ b/src/test/org/apache/commons/collections/AbstractTestMap.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestMap.java,v 1.2 2003/10/05 12:34:46 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/AbstractTestMap.java,v 1.3 2003/10/05 20:47:37 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -151,7 +151,7 @@ import java.util.Set; * @author Rodney Waldhoff * @author Paul Jack * @author Stephen Colebourne - * @version $Revision: 1.2 $ $Date: 2003/10/05 12:34:46 $ + * @version $Revision: 1.3 $ $Date: 2003/10/05 20:47:37 $ */ public abstract class AbstractTestMap extends AbstractTestObject { @@ -303,7 +303,7 @@ public abstract class AbstractTestMap extends AbstractTestObject { */ protected Object[] getNewSampleValues() { Object[] result = new Object[] { - (useNullValue()) ? null : "newnonnullvalue", + (useNullValue() && useDuplicateValues()) ? null : "newnonnullvalue", "newvalue", (useDuplicateValues()) ? "newvalue" : "newvalue2", "newblahv", "newfoov", "newbarv", "newbazv", "newtmpv", "newgoshv", @@ -801,11 +801,91 @@ public abstract class AbstractTestMap extends AbstractTestObject { verify(); } + //----------------------------------------------------------------------- + /** + * Tests that the {@link Map#values} collection is backed by + * the underlying map for clear(). + */ + public void testValuesClearChangesMap() { + if (!isAddRemoveModifiable()) return; + + // clear values, reflected in map + resetFull(); + Collection values = map.values(); + assertTrue(map.size() > 0); + assertTrue(values.size() > 0); + values.clear(); + assertTrue(map.size() == 0); + assertTrue(values.size() == 0); + + // clear map, reflected in values + resetFull(); + values = map.values(); + assertTrue(map.size() > 0); + assertTrue(values.size() > 0); + map.clear(); + assertTrue(map.size() == 0); + assertTrue(values.size() == 0); + } + + /** + * Tests that the {@link Map#keySet} collection is backed by + * the underlying map for clear(). + */ + public void testKeySetClearChangesMap() { + if (!isAddRemoveModifiable()) return; + + // clear values, reflected in map + resetFull(); + Set keySet = map.keySet(); + assertTrue(map.size() > 0); + assertTrue(keySet.size() > 0); + keySet.clear(); + assertTrue(map.size() == 0); + assertTrue(keySet.size() == 0); + + // clear map, reflected in values + resetFull(); + keySet = map.keySet(); + assertTrue(map.size() > 0); + assertTrue(keySet.size() > 0); + map.clear(); + assertTrue(map.size() == 0); + assertTrue(keySet.size() == 0); + } + + /** + * Tests that the {@link Map#entrySet()} collection is backed by + * the underlying map for clear(). + */ + public void testEntrySetClearChangesMap() { + if (!isAddRemoveModifiable()) return; + + // clear values, reflected in map + resetFull(); + Set entrySet = map.entrySet(); + assertTrue(map.size() > 0); + assertTrue(entrySet.size() > 0); + entrySet.clear(); + assertTrue(map.size() == 0); + assertTrue(entrySet.size() == 0); + + // clear map, reflected in values + resetFull(); + entrySet = map.entrySet(); + assertTrue(map.size() > 0); + assertTrue(entrySet.size() > 0); + map.clear(); + assertTrue(map.size() == 0); + assertTrue(entrySet.size() == 0); + } + + //----------------------------------------------------------------------- /** * Tests that the {@link Map#values} collection is backed by * the underlying map by removing from the values collection * and testing if the value was removed from the map. - *
+ *
* We should really test the "vice versa" case--that values removed
* from the map are removed from the values collection--also,
* but that's a more difficult test to construct (lacking a
@@ -813,21 +893,23 @@ public abstract class AbstractTestMap extends AbstractTestObject {
*
* @see http://issues.apache.org/bugzilla/show_bug.cgi?id=9573
*/
- public void testValuesRemovedFromValuesCollectionAreRemovedFromMap() {
+ public void testValuesRemoveChangesMap() {
resetFull();
Object[] sampleValues = getSampleValues();
Collection values = map.values();
- for(int i=0;i