From cfb3754d15bfccea0a709f1b6c1d5fee69c676a0 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 7 Dec 2003 01:21:51 +0000 Subject: [PATCH] Enable LRUMap testing by adding isGetStructuralModify() git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131416 13f79535-47bb-0310-9956-ffa450edef68 --- .../iterators/AbstractTestMapIterator.java | 24 ++++++++++++++----- .../AbstractTestOrderedMapIterator.java | 9 +++---- .../map/AbstractTestIterableMap.java | 8 +++++-- .../collections/map/AbstractTestMap.java | 24 ++++++++++++++++--- .../map/AbstractTestOrderedMap.java | 8 +++++-- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java b/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java index 3d52755f3..31d9f4f20 100644 --- a/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java +++ b/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java,v 1.8 2003/12/02 21:56:34 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestMapIterator.java,v 1.9 2003/12/07 01:21:51 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -74,7 +74,7 @@ import org.apache.commons.collections.MapIterator; * overriding the supportsXxx() methods if necessary. * * @since Commons Collections 3.0 - * @version $Revision: 1.8 $ $Date: 2003/12/02 21:56:34 $ + * @version $Revision: 1.9 $ $Date: 2003/12/07 01:21:51 $ * * @author Stephen Colebourne */ @@ -148,6 +148,16 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator { return true; } + /** + * Whether the get operation on the map structurally modifies the map, + * such as with LRUMap. Default is false. + * + * @return true if the get method structurally modifies the map + */ + public boolean isGetStructuralModify() { + return false; + } + /** * The values to be used in the add and set tests. * Default is two strings. @@ -227,9 +237,10 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator { // getValue Object value = it.getValue(); - assertSame("Value must be mapped to key", map.get(key), value); + if (isGetStructuralModify() == false) { + assertSame("Value must be mapped to key", map.get(key), value); + } assertTrue("Value must be in map", map.containsValue(value)); - assertSame("Value must be mapped to key", map.get(key), value); verify(); } @@ -257,14 +268,15 @@ public abstract class AbstractTestMapIterator extends AbstractTestIterator { } catch (UnsupportedOperationException ex) {} return; } - Object old = it.setValue(newValue); confirmed.put(key, newValue); assertSame("Key must not change after setValue", key, it.getKey()); assertSame("Value must be changed after setValue", newValue, it.getValue()); assertSame("setValue must return old value", value, old); assertEquals("Map must contain key", true, map.containsKey(key)); - assertEquals("Map must not contain old value", false, map.containsValue(old)); + // test against confirmed, as map may contain value twice + assertEquals("Map must not contain old value", + confirmed.containsValue(old), map.containsValue(old)); assertEquals("Map must contain new value", true, map.containsValue(newValue)); verify(); diff --git a/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java b/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java index 9bd636695..567c77816 100644 --- a/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java +++ b/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java,v 1.4 2003/12/03 19:03:21 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/iterators/AbstractTestOrderedMapIterator.java,v 1.5 2003/12/07 01:21:51 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -76,7 +76,7 @@ import org.apache.commons.collections.OrderedMapIterator; * overriding the supportsXxx() methods if necessary. * * @since Commons Collections 3.0 - * @version $Revision: 1.4 $ $Date: 2003/12/03 19:03:21 $ + * @version $Revision: 1.5 $ $Date: 2003/12/07 01:21:51 $ * * @author Stephen Colebourne */ @@ -146,9 +146,10 @@ public abstract class AbstractTestOrderedMapIterator extends AbstractTestMapIter // getValue Object value = it.getValue(); - assertSame("Value must be mapped to key", map.get(key), value); + if (isGetStructuralModify() == false) { + assertSame("Value must be mapped to key", map.get(key), value); + } assertTrue("Value must be in map", map.containsValue(value)); - assertSame("Value must be mapped to key", map.get(key), value); assertEquals(true, it.hasPrevious()); diff --git a/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java b/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java index 9e9e91ab8..8d0b57218 100644 --- a/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java +++ b/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java,v 1.1 2003/12/02 23:51:49 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java,v 1.2 2003/12/07 01:21:51 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -69,7 +69,7 @@ import org.apache.commons.collections.iterators.AbstractTestMapIterator; /** * Abstract test class for {@link IterableMap} methods and contracts. * - * @version $Revision: 1.1 $ $Date: 2003/12/02 23:51:49 $ + * @version $Revision: 1.2 $ $Date: 2003/12/07 01:21:51 $ * * @author Stephen Colebourne */ @@ -165,6 +165,10 @@ public abstract class AbstractTestIterableMap extends AbstractTestMap { public boolean supportsRemove() { return AbstractTestIterableMap.this.isRemoveSupported(); } + + public boolean isGetStructuralModify() { + return AbstractTestIterableMap.this.isGetStructuralModify(); + } public boolean supportsSetValue() { return AbstractTestIterableMap.this.isSetValueSupported(); diff --git a/src/test/org/apache/commons/collections/map/AbstractTestMap.java b/src/test/org/apache/commons/collections/map/AbstractTestMap.java index 3aa9582cf..421614d7a 100644 --- a/src/test/org/apache/commons/collections/map/AbstractTestMap.java +++ b/src/test/org/apache/commons/collections/map/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/map/AbstractTestMap.java,v 1.2 2003/11/18 22:37:17 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/AbstractTestMap.java,v 1.3 2003/12/07 01:21:51 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -105,6 +105,7 @@ import org.apache.commons.collections.set.AbstractTestSet; *
  • {@link #isPutChangeSupported()} *
  • {@link #isSetValueSupported()} *
  • {@link #isRemoveSupported()} + *
  • {@link #isGetStructuralModify()} *
  • {@link #isAllowDuplicateValues()} *
  • {@link #isAllowNullKey()} *
  • {@link #isAllowNullValue()} @@ -158,7 +159,7 @@ import org.apache.commons.collections.set.AbstractTestSet; * @author Rodney Waldhoff * @author Paul Jack * @author Stephen Colebourne - * @version $Revision: 1.2 $ $Date: 2003/11/18 22:37:17 $ + * @version $Revision: 1.3 $ $Date: 2003/12/07 01:21:51 $ */ public abstract class AbstractTestMap extends AbstractTestObject { @@ -246,6 +247,18 @@ public abstract class AbstractTestMap extends AbstractTestObject { return true; } + /** + * Returns true if the maps produced by + * {@link #makeEmptyMap()} and {@link #makeFullMap()} + * can cause structural modification on a get(). The example is LRUMap. + *

    + * Default implementation returns false. + * Override if your map class structurally modifies on get. + */ + public boolean isGetStructuralModify() { + return false; + } + /** * Returns true if the maps produced by * {@link #makeEmptyMap()} and {@link #makeFullMap()} @@ -1159,6 +1172,9 @@ public abstract class AbstractTestMap extends AbstractTestObject { // Entry set should only support remove if map does return AbstractTestMap.this.isRemoveSupported(); } + public boolean isGetStructuralModify() { + return AbstractTestMap.this.isGetStructuralModify(); + } public boolean supportsEmptyCollections() { return AbstractTestMap.this.supportsEmptyCollections(); } @@ -1186,7 +1202,9 @@ public abstract class AbstractTestMap extends AbstractTestObject { Map.Entry entry = (Map.Entry) it.next(); assertEquals(true, AbstractTestMap.this.map.containsKey(entry.getKey())); assertEquals(true, AbstractTestMap.this.map.containsValue(entry.getValue())); - assertEquals(AbstractTestMap.this.map.get(entry.getKey()), entry.getValue()); + if (isGetStructuralModify() == false) { + assertEquals(AbstractTestMap.this.map.get(entry.getKey()), entry.getValue()); + } count++; } assertEquals(collection.size(), count); diff --git a/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java b/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java index c95aec6f9..cd58cd674 100644 --- a/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java +++ b/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java,v 1.4 2003/12/02 23:51:49 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/AbstractTestOrderedMap.java,v 1.5 2003/12/07 01:21:51 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -75,7 +75,7 @@ import org.apache.commons.collections.iterators.AbstractTestOrderedMapIterator; /** * Abstract test class for {@link OrderedMap} methods and contracts. * - * @version $Revision: 1.4 $ $Date: 2003/12/02 23:51:49 $ + * @version $Revision: 1.5 $ $Date: 2003/12/07 01:21:51 $ * * @author Stephen Colebourne */ @@ -227,6 +227,10 @@ public abstract class AbstractTestOrderedMap extends AbstractTestIterableMap { return AbstractTestOrderedMap.this.isRemoveSupported(); } + public boolean isGetStructuralModify() { + return AbstractTestOrderedMap.this.isGetStructuralModify(); + } + public boolean supportsSetValue() { return AbstractTestOrderedMap.this.isSetValueSupported(); }