01: package de.schlund.pfixxml;
02:
03: import de.schlund.pfixxml.util.CacheValueLRU;
04: import junit.framework.TestCase;
05:
06: public class CacheValueLRUTest extends TestCase {
07:
08: public void testLRU() throws Exception {
09: System.out.println("-----testLRU-----");
10: CacheValueLRU<String, String> map = new CacheValueLRU<String, String>(
11: 3);
12: map.put("Key_A", "Val_1");
13: map.put("Key_B", "Val_2");
14: map.put("Key_C", "Val_3");
15: System.out.println(map);
16: assertEquals(3, map.size());
17: assertEquals(3, map.sizeOfUniqueValueEntries());
18: map.put("Key_X", "Val_1");
19: System.out.println(map);
20: assertEquals(4, map.size());
21: assertEquals(3, map.sizeOfUniqueValueEntries());
22: assertEquals(map.get("Key_X"), "Val_1");
23: assertEquals(map.get("Key_A"), "Val_1");
24: assertEquals(map.get("Key_B"), "Val_2");
25: System.out.println(map);
26: map.put("Key_D", "Val_4");
27: assertNull(map.get("Key_C"));
28: System.out.println(map);
29: map.put("Key_E", "Val_5");
30: System.out.println(map);
31: assertNull(map.get("Key_A"));
32: assertNull(map.get("Key_X"));
33: }
34:
35: public void testMultipleKeys() throws Exception {
36: System.out.println("-----testMultipleKeys-----");
37: CacheValueLRU<String, String> map = new CacheValueLRU<String, String>(
38: 3);
39: map.put("Key_A", "Val_1");
40: map.put("Key_B", "Val_2");
41: map.put("Key_C", "Val_3");
42: System.out.println(map);
43: map.put("Key_X", "Val_1");
44: assertEquals(2, map.sizeOfKeyEntriesForValue("Val_1"));
45: System.out.println(map);
46: map.put("Key_X", "Val_2");
47: assertEquals(1, map.sizeOfKeyEntriesForValue("Val_1"));
48: assertEquals(2, map.sizeOfKeyEntriesForValue("Val_2"));
49: System.out.println(map);
50: map.put("Key_X", "Val_3");
51: System.out.println(map);
52: map.remove("Key_X");
53: assertEquals(1, map.sizeOfKeyEntriesForValue("Val_3"));
54: System.out.println(map);
55: map.remove("Key_C");
56: assertEquals(2, map.size());
57: System.out.println(map);
58: }
59: }
|