morgand 02/02/14 12:57:59
Modified: collections/src/test/org/apache/commons/collections
TestLRUMap.java
Log:
unit tests for subclass behaviour
Revision Changes Path
1.6 +72 -4
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestLRUMap.java 13 Feb 2002 23:55:41 -0000 1.5
+++ TestLRUMap.java 14 Feb 2002 20:57:59 -0000 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v
1.5 2002/02/13 23:55:41 morgand Exp $
- * $Revision: 1.5 $
- * $Date: 2002/02/13 23:55:41 $
+ * $Header:
/home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestLRUMap.java,v
1.6 2002/02/14 20:57:59 morgand Exp $
+ * $Revision: 1.6 $
+ * $Date: 2002/02/14 20:57:59 $
*
* ====================================================================
*
@@ -71,7 +71,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.5 2002/02/13 23:55:41 morgand Exp $
+ * @version $Id: TestLRUMap.java,v 1.6 2002/02/14 20:57:59 morgand Exp $
*/
public class TestLRUMap extends TestHashMap
{
@@ -150,5 +150,73 @@
map2.containsKey(new Integer(4)));
}
+ /**
+ * You should be able to subclass LRUMap and perform a
+ * custom action when items are removed automatically
+ * by the LRU algorithm (the removeLRU() method).
+ */
+ public void testLRUSubclass() {
+ LRUCounter counter = new LRUCounter(3);
+ counter.put(new Integer(1),"foo");
+ counter.put(new Integer(2),"foo");
+ counter.put(new Integer(3),"foo");
+ counter.put(new Integer(1),"foo");
+ counter.put(new Integer(4),"foo");
+ counter.put(new Integer(5),"foo");
+ counter.put(new Integer(2),"foo");
+ counter.remove(new Integer(5));
+
+ assertTrue("size should be 2, but was " + counter.size(), counter.size() ==
2);
+ assertTrue("removedCount should be 2 but was " + counter.removedCount,
+ counter.removedCount == 2);
+ }
+
+ /**
+ * You should be able to subclass LRUMap and perform a
+ * custom action when items are removed automatically
+ * or when remove is called manually
+ * by overriding the remove(Object) method.
+ */
+ public void testRemoveSubclass() {
+ RemoveCounter counter = new RemoveCounter(3);
+ counter.put(new Integer(1),"foo");
+ counter.put(new Integer(2),"foo");
+ counter.put(new Integer(3),"foo");
+ counter.put(new Integer(1),"foo");
+ counter.put(new Integer(4),"foo");
+ counter.put(new Integer(5),"foo");
+ counter.put(new Integer(2),"foo");
+ counter.remove(new Integer(5));
+
+ assertTrue("size should be 2, but was " + counter.size(), counter.size() ==
2);
+ assertTrue("removedCount should be 3 but was " + counter.removedCount,
+ counter.removedCount == 3);
+ }
+
+ private class LRUCounter extends LRUMap {
+ int removedCount = 0;
+
+ LRUCounter(int i) {
+ super(i);
+ }
+
+ public Object removeLRU() {
+ ++removedCount;
+ return super.removeLRU();
+ }
+ }
+
+ private class RemoveCounter extends LRUMap {
+ int removedCount = 0;
+
+ RemoveCounter(int i) {
+ super(i);
+ }
+
+ public Object remove(Object o) {
+ ++removedCount;
+ return super.remove(o);
+ }
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>