morgand 02/02/20 14:38:46 Modified: collections/src/test/org/apache/commons/collections TestLRUMap.java TestMap.java TestSequencedHashMap.java Log: 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 Revision Changes Path 1.14 +4 -37 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.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- TestLRUMap.java 20 Feb 2002 20:51:38 -0000 1.13 +++ TestLRUMap.java 20 Feb 2002 22:38:46 -0000 1.14 @@ -1,7 +1,7 @@ /* - * $Header: /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/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 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @author <a href="mailto:[EMAIL PROTECTED]">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 @@ 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. @@ -149,19 +129,6 @@ map2.size() == 3); assertTrue("map should contain the Integer(4) object", 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))); } /** 1.4 +92 -30 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestMap.java 15 Feb 2002 20:48:18 -0000 1.3 +++ TestMap.java 20 Feb 2002 22:38:46 -0000 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/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/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/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 @@ * 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 @@ 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 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 @@ */ /** - * 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 { + } + } 1.5 +1 -1 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TestSequencedHashMap.java 20 Feb 2002 22:17:18 -0000 1.4 +++ TestSequencedHashMap.java 20 Feb 2002 22:38:46 -0000 1.5 @@ -73,7 +73,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a> * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> */ -public class TestSequencedHashMap extends TestMap +public class TestSequencedHashMap extends TestMap implements TestMap.SupportsPut { /** * The instance to experiment on.
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>