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
This commit is contained in:
Stephen Colebourne 2003-12-07 01:21:51 +00:00
parent 5b9d61cdbd
commit cfb3754d15
5 changed files with 56 additions and 17 deletions

View File

@ -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();

View File

@ -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());

View File

@ -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
*/
@ -166,6 +166,10 @@ public abstract class AbstractTestIterableMap extends AbstractTestMap {
return AbstractTestIterableMap.this.isRemoveSupported();
}
public boolean isGetStructuralModify() {
return AbstractTestIterableMap.this.isGetStructuralModify();
}
public boolean supportsSetValue() {
return AbstractTestIterableMap.this.isSetValueSupported();
}

View File

@ -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;
* <li> {@link #isPutChangeSupported()}
* <li> {@link #isSetValueSupported()}
* <li> {@link #isRemoveSupported()}
* <li> {@link #isGetStructuralModify()}
* <li> {@link #isAllowDuplicateValues()}
* <li> {@link #isAllowNullKey()}
* <li> {@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.
* <p>
* 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);

View File

@ -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();
}