1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.onemind.commons.java.datastructure;
22
23 import java.util.TreeSet;
24 import org.onemind.commons.java.datastructure.MruList;
25 import junit.framework.TestCase;
26 /***
27 * Test for MruList
28 * @author TiongHiang Lee (thlee@onemindsoft.org)
29 * @version $Id: MruListTest.java,v 1.2 2004/08/26 12:33:09 thlee Exp $ $Name: $
30 */
31 public class MruListTest extends TestCase
32 {
33
34 /***
35 * Test the MruEntry implementation
36 * @throws Exception if there's problem
37 */
38 public void testMruEntry() throws Exception
39 {
40 TreeSet set = new TreeSet();
41 Object first = new String("first");
42 Object second = new String("second");
43 MruList.MruEntry entry1 = new MruList.MruEntry(first, System.currentTimeMillis());
44 Thread.currentThread().sleep(20);
45 MruList.MruEntry entry2 = new MruList.MruEntry(second, System.currentTimeMillis());
46 set.add(entry1);
47 set.add(entry2);
48 assertEquals(set.iterator().next(), entry2);
49 System.out.println(set);
50 Thread.currentThread().sleep(20);
51 entry1.setLastAccessTime(System.currentTimeMillis());
52 set.remove(entry1);
53 set.add(entry1);
54 System.out.println(set);
55 assertEquals(set.iterator().next(), entry1);
56 }
57
58 /***
59 * Test the MruList
60 * @throws Exception if there's problem
61 */
62 public void testMruList() throws Exception
63 {
64 MruList list = new MruList();
65 Object first = new String("first");
66 Object second = new String("second");
67 list.add(first);
68 Thread.currentThread().sleep(20);
69 list.add(second);
70 System.out.println(list.iterator().next());
71 assertEquals(list.iterator().next(), second);
72 Thread.currentThread().sleep(20);
73 list.add(first);
74 assertEquals(list.iterator().next(), first);
75 }
76
77 /***
78 * Test truncation
79 */
80 public void testTruncate()
81 {
82 MruList list = new MruList(3, 0);
83 for (int i = 0; i < 10; i++)
84 {
85 Integer obj = new Integer(i);
86 list.add(obj);
87 }
88 assertEquals(list.size(), 3);
89 }
90 }