View Javadoc

1   package org.xmlhammer.gui.utils;
2   
3   import junit.framework.Test;
4   import junit.framework.TestCase;
5   import junit.framework.TestSuite;
6   
7   import org.xmlhammer.gui.util.HistoryList;
8   
9   public class HistoryListTest extends TestCase {
10      private static HistoryList<Integer> model = null;
11  
12      protected HistoryListTest(String test) {
13          super(test);
14      }
15  
16      protected void setUp() {
17          // nothing to do
18      }
19  
20      protected void tearDown() {
21          // nothing to do
22      }
23      
24      public void testInit() {
25          model = new HistoryList<Integer>();
26          assertFalse(model.hasNext());
27          assertFalse(model.hasPrevious());
28          
29          assertNull(model.next());
30          assertNull(model.previous());
31          assertNull(model.current());
32      }
33  
34      public void testFirst() {
35          model.put(1);
36          
37          assertFalse(model.hasNext());
38          assertFalse(model.hasPrevious());
39          
40          assertNull(model.next());
41          assertNull(model.previous());
42          assertEquals(new Integer(1), model.current());
43      }
44  
45      public void testAppend() {
46          model.put(2);
47          
48          assertFalse(model.hasNext());
49          assertTrue(model.hasPrevious());
50          
51          assertEquals(new Integer(2), model.current());
52  
53          assertNull(model.next());
54          assertEquals(new Integer(1), model.previous());
55          
56          assertTrue(model.hasNext());
57          assertFalse(model.hasPrevious());
58          
59          assertEquals(new Integer(1), model.current());
60  
61          assertNull(model.previous());
62          assertEquals(new Integer(2), model.next());
63  
64          model.put(3);
65  
66          assertFalse(model.hasNext());
67          assertTrue(model.hasPrevious());
68          
69          assertEquals(new Integer(3), model.current());
70  
71          assertNull(model.next());
72          assertEquals(new Integer(2), model.previous());
73  
74          assertTrue(model.hasNext());
75          assertTrue(model.hasPrevious());
76          
77          assertEquals(new Integer(2), model.current());
78  
79          assertEquals(new Integer(3), model.next());
80          assertEquals(new Integer(3), model.current());
81          assertNull(model.next());
82          assertFalse(model.hasNext());
83          assertTrue(model.hasPrevious());
84  
85          
86          assertEquals(new Integer(2), model.previous());
87          assertEquals(new Integer(2), model.current());
88          assertTrue(model.hasNext());
89          assertTrue(model.hasPrevious());
90  
91          assertEquals(new Integer(1), model.previous());
92          assertEquals(new Integer(1), model.current());
93          assertNull(model.previous());
94          assertTrue(model.hasNext());
95          assertFalse(model.hasPrevious());
96  
97          assertEquals(new Integer(2), model.next());
98          assertEquals(new Integer(2), model.current());
99          assertTrue(model.hasNext());
100         assertTrue(model.hasPrevious());
101 
102         assertEquals(new Integer(3), model.next());
103         assertEquals(new Integer(3), model.current());
104         assertNull(model.next());
105         assertFalse(model.hasNext());
106         assertTrue(model.hasPrevious());
107     }
108     
109     public void testInsert() {
110         assertEquals(new Integer(3), model.last());
111         assertEquals(new Integer(2), model.previous());
112         assertEquals(new Integer(2), model.current());
113         assertTrue(model.hasNext());
114         assertTrue(model.hasPrevious());
115 
116         model.put(new Integer(4));
117         assertEquals(new Integer(4), model.current());
118         assertNull(model.next());
119         assertFalse(model.hasNext());
120         assertTrue(model.hasPrevious());
121         
122         assertEquals(new Integer(2), model.previous());
123         assertEquals(new Integer(2), model.current());
124         assertTrue(model.hasNext());
125         assertTrue(model.hasPrevious());
126 
127         assertEquals(new Integer(1), model.previous());
128         assertEquals(new Integer(1), model.current());
129         
130         assertTrue(model.hasNext());
131         assertFalse(model.hasPrevious());
132         assertNull(model.previous());
133         
134         assertEquals(new Integer(2), model.next());
135         assertEquals(new Integer(2), model.current());
136         assertTrue(model.hasNext());
137         assertTrue(model.hasPrevious());
138 
139         assertEquals(new Integer(4), model.next());
140         assertEquals(new Integer(4), model.current());
141         assertFalse(model.hasNext());
142         assertTrue(model.hasPrevious());
143         assertNull(model.next());
144     }
145 
146     public void testInsertEarly() {
147         assertEquals(new Integer(2), model.previous());
148         assertEquals(new Integer(1), model.previous());
149         assertEquals(new Integer(1), model.current());
150         assertTrue(model.hasNext());
151         assertFalse(model.hasPrevious());
152         assertNull(model.previous());
153 
154         model.put(new Integer(5));
155         assertEquals(new Integer(5), model.current());
156         assertFalse(model.hasNext());
157         assertNull(model.next());
158         assertTrue(model.hasPrevious());
159     }
160 
161     public static Test suite() {
162         TestSuite suite = new TestSuite("XPath Command Line Test");
163         
164         suite.addTest(new HistoryListTest("testInit"));
165         suite.addTest(new HistoryListTest("testFirst"));
166         suite.addTest(new HistoryListTest("testAppend"));
167         suite.addTest(new HistoryListTest("testInsert"));
168         suite.addTest(new HistoryListTest("testInsertEarly"));
169 
170         return suite;
171     }
172 }