blob: 2ee99c4dd8a3596d0cd07dd1a0a4c08259a8d3a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package cgeo.geocaching.utils;
import junit.framework.TestCase;
import java.util.LinkedList;
import java.util.List;
public class MiscUtilsTest extends TestCase {
public static void testBufferEmpty() {
for (final List<String> s: MiscUtils.buffer(new LinkedList<String>(), 10)) {
fail("empty collection should not iterate");
}
}
public static void testMultiple() {
final List<Integer> list = new LinkedList<Integer>();
for (int i = 0; i < 50; i++) {
list.add(i);
}
int count = 0;
for (final List<Integer> subList: MiscUtils.buffer(list, 10)) {
assertEquals("each sublist has the right size", 10, subList.size());
assertEquals("sublist has the right content", count * 10, (int) subList.get(0));
count++;
}
assertEquals("there are the right number of sublists", 5, count);
}
public static void testNonMultiple() {
final List<Integer> list = new LinkedList<Integer>();
for (int i = 0; i < 48; i++) {
list.add(i);
}
int count = 0;
for (final List<Integer> subList: MiscUtils.buffer(list, 10)) {
assertTrue("each sublist has no more than the allowed number of arguments", subList.size() <= 10);
count += subList.size();
}
assertEquals("all the elements were seen", 48, count);
}
public static void testArguments() {
try {
MiscUtils.buffer(new LinkedList<Integer>(), 0);
fail("an exception should be raised");
} catch (final IllegalArgumentException e) {
// Ok
} catch (final Exception e) {
fail("bad exception raised: " + e);
}
}
}
|