1 package org.unicode.cldr.unittest;
2 
3 import java.util.Iterator;
4 
5 import org.unicode.cldr.util.LruMap;
6 
7 import com.ibm.icu.dev.test.TestFmwk;
8 
9 public class TestLruMap extends TestFmwk {
main(String[] args)10     public static void main(String[] args) {
11         new TestLruMap().run(args);
12     }
13 
TestMapOrdering()14     public void TestMapOrdering() {
15         LruMap<String, Integer> map = new LruMap<String, Integer>(3);
16         map.put("a", 1);
17         map.put("b", 2);
18         map.put("c", 3);
19         Iterator<String> iterator = map.keySet().iterator();
20         assertEquals("Map Size", 3, map.size());
21         assertEquals("Oldest item", "a", iterator.next());
22         assertEquals("Second item", "b", iterator.next());
23         assertEquals("Newest item", "c", iterator.next());
24 
25         map.get("b");
26         iterator = map.keySet().iterator();
27         assertEquals("Map Size", 3, map.size());
28         assertEquals("Oldest item", "a", iterator.next());
29         assertEquals("Second item", "c", iterator.next());
30         assertEquals("Newest item", "b", iterator.next());
31 
32         map.put("d", 4);
33         iterator = map.keySet().iterator();
34         assertEquals("Map Size", 3, map.size());
35         assertEquals("Oldest item", "c", iterator.next());
36         assertEquals("Second item", "b", iterator.next());
37         assertEquals("Newest item", "d", iterator.next());
38     }
39 }