1 package de.fu_berlin.ties.util;
2
3 import junit.framework.TestCase;
4
5 import de.fu_berlin.ties.util.ListEntry;
6
7
8 /***
9 * Generated by JUnitDoclet, a tool provided by
10 * ObjectFab GmbH under LGPL.
11 * Please see www.junitdoclet.org, www.gnu.org
12 * and www.objectfab.de for informations about
13 * the tool, the licence and the authors.
14 */
15
16
17 public class ListEntryTest
18
19 extends TestCase
20
21 {
22
23 ListEntry first, second, last;
24
25
26 public ListEntryTest(String name) {
27
28 super(name);
29
30 }
31
32 public de.fu_berlin.ties.util.ListEntry createInstance() throws Exception {
33
34 return new ListEntry();
35
36 }
37
38 protected void setUp() throws Exception {
39
40 super.setUp();
41 first = createInstance();
42 last = createInstance();
43 second = new ListEntry(first, last);
44
45 }
46
47 protected void tearDown() throws Exception {
48
49 first = second = last = null;
50 super.tearDown();
51
52 }
53
54 public void testHasNext() throws Exception {
55
56 assertTrue(first.hasNext());
57 assertTrue(second.hasNext());
58 assertFalse(last.hasNext());
59
60 }
61
62 public void testHasPrevious() throws Exception {
63
64 assertFalse(first.hasPrevious());
65 assertTrue(second.hasPrevious());
66 assertTrue(last.hasPrevious());
67
68 }
69
70 public void testInsertAfter() throws Exception {
71
72 final ListEntry newEntry = createInstance();
73 second.insertAfter(newEntry);
74 assertSame(second.next(), newEntry);
75 assertSame(newEntry.previous(), second);
76 assertSame(newEntry.next(), last);
77 assertSame(last.previous(), newEntry);
78
79 final ListEntry newFirst = createInstance();
80 newFirst.insertAfter(first);
81 assertSame(newFirst.next(), first);
82 assertSame(first.previous(), newFirst);
83 assertSame(first.next(), second);
84 assertSame(second.previous(), first);
85 assertFalse(newFirst.hasPrevious());
86
87 final ListEntry newLast = createInstance();
88 last.insertAfter(newLast);
89 assertSame(last.next(), newLast);
90 assertSame(newLast.previous(), last);
91 assertFalse(newLast.hasNext());
92
93 }
94
95 public void testInsertBefore() throws Exception {
96
97 final ListEntry newEntry = createInstance();
98 second.insertBefore(newEntry);
99 assertSame(second.previous(), newEntry);
100 assertSame(newEntry.next(), second);
101 assertSame(newEntry.previous(), first);
102 assertSame(first.next(), newEntry);
103
104 final ListEntry newFirst = createInstance();
105 first.insertBefore(newFirst);
106 assertSame(newFirst.next(), first);
107 assertSame(first.previous(), newFirst);
108 assertSame(first.next(), newEntry);
109 assertSame(newEntry.previous(), first);
110 assertFalse(newFirst.hasPrevious());
111
112 final ListEntry newLast = createInstance();
113 newLast.insertBefore(last);
114 assertSame(last.next(), newLast);
115 assertSame(newLast.previous(), last);
116 assertFalse(newLast.hasNext());
117
118 }
119
120 public void testNext() throws Exception {
121
122 assertSame(first.next(), second);
123 assertSame(second.next(), last);
124 assertNull(last.next());
125
126 }
127
128 public void testPrevious() throws Exception {
129
130 assertNull(first.previous());
131 assertSame(second.previous(), first);
132 assertSame(last.previous(), second);
133
134 }
135
136 public void testRemove() throws Exception {
137
138 second.remove();
139 assertFalse(second.hasNext());
140 assertFalse(second.hasPrevious());
141 assertSame(first.next(), last);
142 assertSame(last.previous(), first);
143
144 last.remove();
145 assertFalse(last.hasNext());
146 assertFalse(last.hasPrevious());
147 assertFalse(first.hasNext());
148
149 }
150
151 public void testToString() throws Exception {
152
153 final String firstDesc = first.toString();
154 final String secondDesc = second.toString();
155 assertTrue(firstDesc.matches(".*ListEntry.*previous=false.*next=true.*"));
156 assertTrue(secondDesc.matches(".*ListEntry.*previous=true.*next=true.*"));
157
158 }
159
160
161
162 /***
163 * JUnitDoclet moves marker to this method, if there is not match
164 * for them in the regenerated code and if the marker is not empty.
165 * This way, no test gets lost when regenerating after renaming.
166 * Method testVault is supposed to be empty.
167 */
168 public void testVault() throws Exception {
169
170
171 }
172
173 public static void main(String[] args) {
174
175 junit.textui.TestRunner.run(ListEntryTest.class);
176
177 }
178 }