Skip to content

Commit 51186c1

Browse files
sfuhrmgarydgregory
authored andcommitted
Moved tests from JUnit 3 to JUnit 4 nomenclature. Closes #44.
1 parent 11eca16 commit 51186c1

10 files changed

Lines changed: 103 additions & 26 deletions

src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@
2222
import java.util.ListIterator;
2323
import java.util.Random;
2424

25-
import junit.framework.TestCase;
2625
import org.apache.commons.collections4.Predicate;
2726
import org.apache.commons.collections4.PredicateUtils;
2827
import org.apache.commons.collections4.list.GrowthList;
28+
import org.junit.After;
2929
import org.junit.Assert;
30+
import org.junit.Before;
31+
import org.junit.Test;
32+
33+
import static org.junit.Assert.*;
3034

3135
/**
3236
* Tests the FilterListIterator class.
3337
*
3438
*/
3539
@SuppressWarnings("boxing")
36-
public class FilterListIteratorTest extends TestCase {
40+
public class FilterListIteratorTest {
3741

3842
private ArrayList<Integer> list = null;
3943
private ArrayList<Integer> odds = null;
@@ -49,7 +53,7 @@ public class FilterListIteratorTest extends TestCase {
4953
private Predicate<Integer> fourPred = null;
5054
private final Random random = new Random();
5155

52-
@Override
56+
@Before
5357
public void setUp() {
5458
list = new ArrayList<>();
5559
odds = new ArrayList<>();
@@ -110,7 +114,7 @@ public boolean evaluate(final Integer x) {
110114

111115
}
112116

113-
@Override
117+
@After
114118
public void tearDown() throws Exception {
115119
list = null;
116120
odds = null;
@@ -126,11 +130,13 @@ public void tearDown() throws Exception {
126130
fourPred = null;
127131
}
128132

133+
@Test
129134
public void testWalkLists() {
130135
// this just confirms that our walkLists method works OK
131136
walkLists(list,list.listIterator());
132137
}
133138

139+
@Test
134140
public void testManual() {
135141
// do this one "by hand" as a sanity check
136142
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), threePred);
@@ -190,36 +196,43 @@ public void testManual() {
190196
assertEquals(Integer.valueOf(9), filtered.previous());
191197
}
192198

199+
@Test
193200
public void testTruePredicate() {
194201
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), truePred);
195202
walkLists(list, filtered);
196203
}
197204

205+
@Test
198206
public void testFalsePredicate() {
199207
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), falsePred);
200208
walkLists(new ArrayList<Integer>(), filtered);
201209
}
202210

211+
@Test
203212
public void testEvens() {
204213
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), evenPred);
205214
walkLists(evens, filtered);
206215
}
207216

217+
@Test
208218
public void testOdds() {
209219
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), oddPred);
210220
walkLists(odds, filtered);
211221
}
212222

223+
@Test
213224
public void testThrees() {
214225
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), threePred);
215226
walkLists(threes, filtered);
216227
}
217228

229+
@Test
218230
public void testFours() {
219231
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), fourPred);
220232
walkLists(fours, filtered);
221233
}
222234

235+
@Test
223236
public void testNestedSixes() {
224237
final FilterListIterator<Integer> filtered = new FilterListIterator<>(
225238
new FilterListIterator<>(list.listIterator(), threePred),
@@ -228,6 +241,7 @@ public void testNestedSixes() {
228241
walkLists(sixes, filtered);
229242
}
230243

244+
@Test
231245
public void testNestedSixes2() {
232246
final FilterListIterator<Integer> filtered = new FilterListIterator<>(
233247
new FilterListIterator<>(list.listIterator(), evenPred),
@@ -236,6 +250,7 @@ public void testNestedSixes2() {
236250
walkLists(sixes, filtered);
237251
}
238252

253+
@Test
239254
public void testNestedSixes3() {
240255
final FilterListIterator<Integer> filtered = new FilterListIterator<>(
241256
new FilterListIterator<>(list.listIterator(), threePred),
@@ -244,6 +259,7 @@ public void testNestedSixes3() {
244259
walkLists(sixes, new FilterListIterator<>(filtered, truePred));
245260
}
246261

262+
@Test
247263
public void testNextChangesPrevious() {
248264
{
249265
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), threePred);
@@ -256,6 +272,7 @@ public void testNextChangesPrevious() {
256272
}
257273
}
258274

275+
@Test
259276
public void testPreviousChangesNext() {
260277
{
261278
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), threePred);
@@ -271,6 +288,7 @@ public void testPreviousChangesNext() {
271288
}
272289
}
273290

291+
@Test
274292
public void testFailingHasNextBug() {
275293
final FilterListIterator<Integer> filtered = new FilterListIterator<>(list.listIterator(), fourPred);
276294
final ListIterator<Integer> expected = fours.listIterator();
@@ -286,6 +304,7 @@ public void testFailingHasNextBug() {
286304
/**
287305
* Test for {@link "https://issues.apache.org/jira/browse/COLLECTIONS-360 COLLECTIONS-360"}
288306
*/
307+
@Test
289308
public void testCollections360() throws Throwable {
290309
final Collection<Predicate<Object>> var7 = new GrowthList<>();
291310
final Predicate<Object> var9 = PredicateUtils.anyPredicate(var7);

src/test/java/org/apache/commons/collections4/iterators/IteratorEnumerationTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
import java.util.Iterator;
2222
import java.util.NoSuchElementException;
2323

24-
import junit.framework.TestCase;
24+
import org.junit.Test;
25+
import static org.junit.Assert.*;
2526

2627
/**
2728
* Tests the IteratorEnumeration.
2829
*
2930
*/
30-
public class IteratorEnumerationTest extends TestCase {
31+
public class IteratorEnumerationTest {
3132

33+
@Test
3234
public void testEnumeration() {
3335
final Iterator<String> iterator = Arrays.asList("a", "b", "c").iterator();
3436
final IteratorEnumeration<String> enumeration = new IteratorEnumeration<>(iterator);

src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@
2121
import java.util.List;
2222
import java.util.NoSuchElementException;
2323

24-
import junit.framework.TestCase;
24+
import org.junit.Test;
25+
26+
import static org.junit.Assert.*;
2527

2628
/**
2729
* Tests the LoopingIterator class.
2830
*
2931
*/
30-
public class LoopingIteratorTest extends TestCase {
32+
public class LoopingIteratorTest {
3133

3234
/**
3335
* Tests constructor exception.
3436
*/
37+
@Test
3538
public void testConstructorEx() throws Exception {
3639
try {
3740
new LoopingIterator<>(null);
@@ -44,6 +47,7 @@ public void testConstructorEx() throws Exception {
4447
* Tests whether an empty looping iterator works as designed.
4548
* @throws Exception If something unexpected occurs.
4649
*/
50+
@Test
4751
public void testLooping0() throws Exception {
4852
final List<Object> list = new ArrayList<>();
4953
final LoopingIterator<Object> loop = new LoopingIterator<>(list);
@@ -60,6 +64,7 @@ public void testLooping0() throws Exception {
6064
* Tests whether a populated looping iterator works as designed.
6165
* @throws Exception If something unexpected occurs.
6266
*/
67+
@Test
6368
public void testLooping1() throws Exception {
6469
final List<String> list = Arrays.asList("a");
6570
final LoopingIterator<String> loop = new LoopingIterator<>(list);
@@ -79,6 +84,7 @@ public void testLooping1() throws Exception {
7984
* Tests whether a populated looping iterator works as designed.
8085
* @throws Exception If something unexpected occurs.
8186
*/
87+
@Test
8288
public void testLooping2() throws Exception {
8389
final List<String> list = Arrays.asList("a", "b");
8490
final LoopingIterator<String> loop = new LoopingIterator<>(list);
@@ -98,6 +104,7 @@ public void testLooping2() throws Exception {
98104
* Tests whether a populated looping iterator works as designed.
99105
* @throws Exception If something unexpected occurs.
100106
*/
107+
@Test
101108
public void testLooping3() throws Exception {
102109
final List<String> list = Arrays.asList("a", "b", "c");
103110
final LoopingIterator<String> loop = new LoopingIterator<>(list);
@@ -120,6 +127,7 @@ public void testLooping3() throws Exception {
120127
* Tests the remove() method on a LoopingIterator wrapped ArrayList.
121128
* @throws Exception If something unexpected occurs.
122129
*/
130+
@Test
123131
public void testRemoving1() throws Exception {
124132
final List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c"));
125133
final LoopingIterator<String> loop = new LoopingIterator<>(list);
@@ -152,6 +160,7 @@ public void testRemoving1() throws Exception {
152160
* Tests the reset() method on a LoopingIterator wrapped ArrayList.
153161
* @throws Exception If something unexpected occurs.
154162
*/
163+
@Test
155164
public void testReset() throws Exception {
156165
final List<String> list = Arrays.asList("a", "b", "c");
157166
final LoopingIterator<String> loop = new LoopingIterator<>(list);
@@ -174,6 +183,7 @@ public void testReset() throws Exception {
174183
* Tests the size() method on a LoopingIterator wrapped ArrayList.
175184
* @throws Exception If something unexpected occurs.
176185
*/
186+
@Test
177187
public void testSize() throws Exception {
178188
final List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c"));
179189
final LoopingIterator<String> loop = new LoopingIterator<>(list);

src/test/java/org/apache/commons/collections4/iterators/LoopingListIteratorTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@
2121
import java.util.List;
2222
import java.util.NoSuchElementException;
2323

24-
import junit.framework.TestCase;
24+
import org.junit.Test;
25+
import static org.junit.Assert.*;
2526

2627
/**
2728
* Tests the LoopingListIterator class.
2829
*
2930
*/
30-
public class LoopingListIteratorTest extends TestCase {
31+
public class LoopingListIteratorTest {
3132

3233
/**
3334
* Tests constructor exception.
3435
*/
36+
@Test
3537
public void testConstructorEx() throws Exception {
3638
try {
3739
new LoopingListIterator<>(null);
@@ -43,6 +45,7 @@ public void testConstructorEx() throws Exception {
4345
/**
4446
* Tests whether an empty looping list iterator works.
4547
*/
48+
@Test
4649
public void testLooping0() throws Exception {
4750
final List<Object> list = new ArrayList<>();
4851
final LoopingListIterator<Object> loop = new LoopingListIterator<>(list);
@@ -66,6 +69,7 @@ public void testLooping0() throws Exception {
6669
* Tests whether a looping list iterator works on a list with only
6770
* one element.
6871
*/
72+
@Test
6973
public void testLooping1() throws Exception {
7074
final List<String> list = Arrays.asList("a");
7175
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a>
@@ -93,6 +97,7 @@ public void testLooping1() throws Exception {
9397
* Tests whether a looping list iterator works on a list with two
9498
* elements.
9599
*/
100+
@Test
96101
public void testLooping2() throws Exception {
97102
final List<String> list = Arrays.asList("a", "b");
98103
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a> b
@@ -123,6 +128,7 @@ public void testLooping2() throws Exception {
123128
* Tests jogging back and forth between two elements, but not over
124129
* the begin/end boundary of the list.
125130
*/
131+
@Test
126132
public void testJoggingNotOverBoundary() {
127133
final List<String> list = Arrays.asList("a", "b");
128134
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a> b
@@ -143,6 +149,7 @@ public void testJoggingNotOverBoundary() {
143149
* Tests jogging back and forth between two elements over the
144150
* begin/end boundary of the list.
145151
*/
152+
@Test
146153
public void testJoggingOverBoundary() {
147154
final List<String> list = Arrays.asList("a", "b");
148155
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a> b
@@ -161,6 +168,7 @@ public void testJoggingOverBoundary() {
161168
/**
162169
* Tests removing an element from a wrapped ArrayList.
163170
*/
171+
@Test
164172
public void testRemovingElementsAndIteratingForward() {
165173
final List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c"));
166174
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a> b c
@@ -191,6 +199,7 @@ public void testRemovingElementsAndIteratingForward() {
191199
/**
192200
* Tests removing an element from a wrapped ArrayList.
193201
*/
202+
@Test
194203
public void testRemovingElementsAndIteratingBackwards() {
195204
final List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c"));
196205
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a> b c
@@ -221,6 +230,7 @@ public void testRemovingElementsAndIteratingBackwards() {
221230
/**
222231
* Tests the reset method.
223232
*/
233+
@Test
224234
public void testReset() {
225235
final List<String> list = Arrays.asList("a", "b", "c");
226236
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a> b c
@@ -248,6 +258,7 @@ public void testReset() {
248258
/**
249259
* Tests the add method.
250260
*/
261+
@Test
251262
public void testAdd() {
252263
List<String> list = new ArrayList<>(Arrays.asList("b", "e", "f"));
253264
LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <b> e f
@@ -302,6 +313,7 @@ public void testAdd() {
302313
/**
303314
* Tests nextIndex and previousIndex.
304315
*/
316+
@Test
305317
public void testNextAndPreviousIndex() {
306318
final List<String> list = Arrays.asList("a", "b", "c");
307319
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <a> b c
@@ -333,6 +345,7 @@ public void testNextAndPreviousIndex() {
333345
/**
334346
* Tests using the set method to change elements.
335347
*/
348+
@Test
336349
public void testSet() {
337350
final List<String> list = Arrays.asList("q", "r", "z");
338351
final LoopingListIterator<String> loop = new LoopingListIterator<>(list); // <q> r z

0 commit comments

Comments
 (0)