KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > util > OrderRetainingMapTest


1 package com.thoughtworks.xstream.core.util;
2
3 import junit.framework.TestCase;
4
5 import java.util.Map JavaDoc;
6 import java.util.Iterator JavaDoc;
7
8 public class OrderRetainingMapTest extends TestCase {
9     private Map JavaDoc map;
10
11     private void assertNextEquals(Object JavaDoc expected, Iterator JavaDoc iterator) {
12         assertTrue("Expected to pull of another item from iterator : " + expected, iterator.hasNext());
13         assertEquals(expected, iterator.next());
14     }
15
16     private void assertNextEntryEquals(Object JavaDoc expectedKey, Object JavaDoc expectedValue, Iterator JavaDoc iterator) {
17         assertTrue("Expected to pull of another item from iterator : " + expectedKey + "=" + expectedValue, iterator.hasNext());
18         Map.Entry JavaDoc actual = (Map.Entry JavaDoc) iterator.next();
19         assertEquals(expectedKey, actual.getKey());
20         assertEquals(expectedValue, actual.getValue());
21     }
22
23     private void assertNoMore(Iterator JavaDoc iterator) {
24         assertFalse("Should be no more items in iterator", iterator.hasNext());
25     }
26
27     protected void setUp() throws Exception JavaDoc {
28         super.setUp();
29         map = new OrderRetainingMap();
30         map.put("one", "ONE");
31         map.put("two", "TWO");
32         map.put("three", "THREE");
33         map.put("four", "FOUR");
34     }
35
36     public void testMaintainsOrderOfKeySet() {
37         Iterator JavaDoc keySetIterator = map.keySet().iterator();
38         assertNextEquals("one", keySetIterator);
39         assertNextEquals("two", keySetIterator);
40         assertNextEquals("three", keySetIterator);
41         assertNextEquals("four", keySetIterator);
42         assertNoMore(keySetIterator);
43     }
44
45     public void testMaintainsOrderOfValues() {
46         Iterator JavaDoc valuesIterator = map.values().iterator();
47         assertNextEquals("ONE", valuesIterator);
48         assertNextEquals("TWO", valuesIterator);
49         assertNextEquals("THREE", valuesIterator);
50         assertNextEquals("FOUR", valuesIterator);
51         assertNoMore(valuesIterator);
52     }
53
54     // TODO
55
public void TODOtestMaintainsOrderOfEntries() {
56         Iterator JavaDoc entrySetIterator = map.entrySet().iterator();
57         assertNextEntryEquals("one", "ONE", entrySetIterator);
58         assertNextEntryEquals("two", "TWO", entrySetIterator);
59         assertNextEntryEquals("three", "THREE", entrySetIterator);
60         assertNextEntryEquals("four", "FOUR", entrySetIterator);
61         assertNoMore(entrySetIterator);
62     }
63
64 }
65
Popular Tags