moved some generic map tests up to TestMap, and implemented a marker
interface to indicate when a TestMap class can test put(Object,Object) operations git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130542 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e4a9a024e7
commit
787edf0f34
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.13 2002/02/20 20:51:38 morgand Exp $
|
||||
* $Revision: 1.13 $
|
||||
* $Date: 2002/02/20 20:51:38 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/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 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -77,7 +77,7 @@ import java.util.HashMap;
|
|||
*
|
||||
* @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.13 2002/02/20 20:51:38 morgand Exp $
|
||||
* @version $Id: TestLRUMap.java,v 1.14 2002/02/20 22:38:46 morgand Exp $
|
||||
*/
|
||||
public class TestLRUMap extends TestSequencedHashMap
|
||||
{
|
||||
|
@ -110,26 +110,6 @@ public class TestLRUMap extends TestSequencedHashMap
|
|||
assertTrue("LRU should not exist", map2.get(new Integer(1)) == null);
|
||||
}
|
||||
|
||||
public void testMultiplePuts() {
|
||||
LRUMap map2 = new LRUMap(2);
|
||||
map2.put(new Integer(4),"foo");
|
||||
map2.put(new Integer(4),"bar");
|
||||
map2.put(new Integer(4),"foo");
|
||||
map2.put(new Integer(4),"bar");
|
||||
|
||||
assertTrue("same key different value",map2.get(new Integer(4)).equals("bar"));
|
||||
}
|
||||
|
||||
public void testCapacity() {
|
||||
LRUMap map2 = new LRUMap(3);
|
||||
map2.put(new Integer(1),"foo");
|
||||
map2.put(new Integer(2),"foo");
|
||||
map2.put(new Integer(3),"foo");
|
||||
map2.put(new Integer(1),"foo");
|
||||
|
||||
assertTrue("size of Map should be 3, but was " + map2.size(), map2.size() == 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that putAll(Map) does not cause the LRUMap
|
||||
* to exceed its maxiumum size.
|
||||
|
@ -151,19 +131,6 @@ public class TestLRUMap extends TestSequencedHashMap
|
|||
map2.containsKey(new Integer(4)));
|
||||
}
|
||||
|
||||
|
||||
public void testMapSupportsNullValues() {
|
||||
Map map = makeMap();
|
||||
map.put(new Integer(1),"foo");
|
||||
|
||||
assertTrue("no null values in Map",map.containsValue(null) == false);
|
||||
|
||||
map.put(new Integer(2),null);
|
||||
|
||||
assertTrue("null value in Map",map.containsValue(null));
|
||||
assertTrue("key to a null value",map.containsKey(new Integer(2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the size of the map is reduced immediately
|
||||
* when setMaximumSize(int) is called
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3 2002/02/15 20:48:18 morgand Exp $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2002/02/15 20:48:18 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.4 2002/02/20 22:38:46 morgand Exp $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/02/20 22:38:46 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -76,7 +76,7 @@ import java.util.Collection;
|
|||
* test case (method) your {@link Map} fails.
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
* @version $Id: TestMap.java,v 1.3 2002/02/15 20:48:18 morgand Exp $
|
||||
* @version $Id: TestMap.java,v 1.4 2002/02/20 22:38:46 morgand Exp $
|
||||
*/
|
||||
public abstract class TestMap extends TestObject {
|
||||
public TestMap(String testName) {
|
||||
|
@ -92,13 +92,33 @@ public abstract class TestMap extends TestObject {
|
|||
return makeMap();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
// optional operation
|
||||
public void testMapClear() {
|
||||
// XXX finish me
|
||||
/**
|
||||
* Try to put the given pair into the given Collection.
|
||||
*
|
||||
* Fails any Throwable except UnsupportedOperationException,
|
||||
* ClassCastException, or IllegalArgumentException
|
||||
* or NullPointerException is thrown.
|
||||
*/
|
||||
protected Object tryToPut(Map map, Object key, Object val) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public void testMapContainsKey() {
|
||||
// XXX finish me
|
||||
}
|
||||
|
@ -130,6 +150,64 @@ public abstract class TestMap extends TestObject {
|
|||
public void testMapKeySet() {
|
||||
// XXX finish me
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//-------TEST AGAINST OPTIONAL OPERATIONS, ENABLE IN TEST SUBCLASSES
|
||||
|
||||
public void testMapSupportsNullValues() {
|
||||
|
||||
if ((this instanceof TestMap.SupportsPut) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map map = makeMap();
|
||||
map.put(new Integer(1),"foo");
|
||||
|
||||
assertTrue("no null values in Map",map.containsValue(null) == false);
|
||||
|
||||
map.put(new Integer(2),null);
|
||||
|
||||
assertTrue("null value in Map",map.containsValue(null));
|
||||
assertTrue("key to a null value",map.containsKey(new Integer(2)));
|
||||
}
|
||||
|
||||
public void testMultiplePuts() {
|
||||
|
||||
if ((this instanceof TestMap.SupportsPut) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map map = makeMap();
|
||||
map.put(new Integer(4),"foo");
|
||||
map.put(new Integer(4),"bar");
|
||||
map.put(new Integer(4),"foo");
|
||||
map.put(new Integer(4),"bar");
|
||||
|
||||
assertTrue("same key different value",map.get(new Integer(4)).equals("bar"));
|
||||
}
|
||||
|
||||
|
||||
public void testCapacity() {
|
||||
|
||||
if ((this instanceof TestMap.SupportsPut) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map map = makeMap();
|
||||
map.put(new Integer(1),"foo");
|
||||
map.put(new Integer(2),"foo");
|
||||
map.put(new Integer(3),"foo");
|
||||
map.put(new Integer(1),"foo");
|
||||
|
||||
assertTrue("size of Map should be 3, but was " + map.size(), map.size() == 3);
|
||||
}
|
||||
|
||||
/*
|
||||
// optional operation
|
||||
public void testMapClear() {
|
||||
// XXX finish me
|
||||
}
|
||||
|
||||
// optional operation
|
||||
public void testMapPut() {
|
||||
|
@ -157,27 +235,11 @@ public abstract class TestMap extends TestObject {
|
|||
*/
|
||||
|
||||
/**
|
||||
* Try to put the given pair into the given Collection.
|
||||
*
|
||||
* Fails any Throwable except UnsupportedOperationException,
|
||||
* ClassCastException, or IllegalArgumentException
|
||||
* or NullPointerException is thrown.
|
||||
* Marker interface, indicating that a TestMap subclass
|
||||
* can test put(Object,Object) operations.
|
||||
*/
|
||||
protected Object tryToPut(Map map, Object key, Object val) {
|
||||
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
|
||||
}
|
||||
public interface SupportsPut {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ import junit.framework.TestSuite;
|
|||
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
|
||||
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
|
||||
*/
|
||||
public class TestSequencedHashMap extends TestMap
|
||||
public class TestSequencedHashMap extends TestMap implements TestMap.SupportsPut
|
||||
{
|
||||
/**
|
||||
* The instance to experiment on.
|
||||
|
|
Loading…
Reference in New Issue