1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.iterators;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22
23 import java.util.Iterator;
24 import java.util.NoSuchElementException;
25
26 import org.junit.jupiter.api.Test;
27
28
29
30
31
32
33
34
35 public class ArrayIteratorTest<E> extends AbstractIteratorTest<E> {
36
37 protected String[] testArray = { "One", "Two", "Three" };
38
39 @Override
40 public ArrayIterator<E> makeEmptyIterator() {
41 return new ArrayIterator<>(new Object[0]);
42 }
43
44 @Override
45 public ArrayIterator<E> makeObject() {
46 return new ArrayIterator<>(testArray);
47 }
48
49 @Override
50 public boolean supportsRemove() {
51 return false;
52 }
53
54 @Test
55 public void testIterator() {
56 final Iterator<E> iter = makeObject();
57 for (final String testValue : testArray) {
58 final E iterValue = iter.next();
59
60 assertEquals(testValue, iterValue, "Iteration value is correct");
61 }
62
63 assertFalse(iter.hasNext(), "Iterator should now be empty");
64
65 assertThrows(NoSuchElementException.class, iter::next, "NoSuchElementException must be thrown");
66 }
67
68 @Test
69 public void testNullArray() {
70 assertThrows(NullPointerException.class, () -> new ArrayIterator<>(null));
71 }
72
73 @Test
74 public void testReset() {
75 final ArrayIterator<E> it = makeObject();
76 it.next();
77 it.reset();
78 assertEquals("One", it.next());
79 }
80
81 }