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 public class ArrayIteratorTest<E> extends AbstractIteratorTest<E> {
34
35 protected String[] testArray = { "One", "Two", "Three" };
36
37 public ArrayIteratorTest() {
38 super(ArrayIteratorTest.class.getSimpleName());
39 }
40
41 @Override
42 public ArrayIterator<E> makeEmptyIterator() {
43 return new ArrayIterator<>(new Object[0]);
44 }
45
46 @Override
47 public ArrayIterator<E> makeObject() {
48 return new ArrayIterator<>(testArray);
49 }
50
51 @Override
52 public boolean supportsRemove() {
53 return false;
54 }
55
56 @Test
57 public void testIterator() {
58 final Iterator<E> iter = makeObject();
59 for (final String testValue : testArray) {
60 final E iterValue = iter.next();
61
62 assertEquals(testValue, iterValue, "Iteration value is correct");
63 }
64
65 assertFalse(iter.hasNext(), "Iterator should now be empty");
66
67 assertThrows(NoSuchElementException.class, iter::next, "NoSuchElementException must be thrown");
68 }
69
70 @Test
71 public void testNullArray() {
72 assertThrows(NullPointerException.class, () -> new ArrayIterator<>(null));
73 }
74
75 @Test
76 public void testReset() {
77 final ArrayIterator<E> it = makeObject();
78 it.next();
79 it.reset();
80 assertEquals("One", it.next());
81 }
82
83 }