summaryrefslogtreecommitdiff
path: root/src/test/java/bjc/data/CircularIteratorTest.java
blob: 8091e1ca1a7bf07d72a9d616048546108cd7b95e (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
55
56
57
package bjc.data;

import static bjc.TestUtils.*;
import java.util.*;

import org.junit.Test;

/**
 * Test for circular iterators.,
 *
 * @author bjculkin
 *
 */
public class CircularIteratorTest {
	/**
	 * Test regular repetition of the entire iterator.
	 */
	@Test
	public void testRegular() {
		List<String> lst = Arrays.asList("a", "b", "c");

		CircularIterator<String> itr = new CircularIterator<>(lst);

		// Check we get initial values correctly, and have more remaining
		assertIteratorEquals(true, itr, "a", "b", "c");

		// Check we repeat correctly, and can still repeat
		assertIteratorEquals(true, itr, "a", "b", "c");
	}

	/**
	 * Test that the last element repeats correctly.
	 */
	@Test
	public void testRepLast() {
		List<String> lst = Arrays.asList("a", "b", "c");

		CircularIterator<String> itr = new CircularIterator<>(lst, false);

		// Check we get initial values correctly, and have more remaining
		assertIteratorEquals(true, itr, "a", "b", "c");

		// Check we repeat correctly, and can still repeat
		assertIteratorEquals(true, itr, "c", "c", "c");
	}
	
	/**
	 * Test that remove throws an exception.
	 */
	@Test(expected = UnsupportedOperationException.class)
	public void testRemove() {
		Iterator<String> arrayItr = new ArrayIterator<>("a", "b");
		CircularIterator<String> itr = new CircularIterator<>(() -> arrayItr);
		
		itr.remove();
	}
}