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.assertNotSame;
20 import static org.junit.jupiter.api.Assertions.assertSame;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.Iterator;
28 import java.util.List;
29
30 import org.apache.commons.collections4.Unmodifiable;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33
34
35
36
37 public class UnmodifiableIteratorTest<E> extends AbstractIteratorTest<E> {
38
39 protected String[] testArray = { "One", "Two", "Three" };
40 protected List<E> testList;
41
42 public UnmodifiableIteratorTest() {
43 super(UnmodifiableIteratorTest.class.getSimpleName());
44 }
45
46 @Override
47 public Iterator<E> makeEmptyIterator() {
48 return UnmodifiableIterator.unmodifiableIterator(Collections.<E>emptyList().iterator());
49 }
50
51 @Override
52 public Iterator<E> makeObject() {
53 return UnmodifiableIterator.unmodifiableIterator(testList.iterator());
54 }
55
56
57
58
59 @SuppressWarnings("unchecked")
60 @BeforeEach
61 protected void setUp() throws Exception {
62 testList = new ArrayList<>(Arrays.asList((E[]) testArray));
63 }
64
65 @Override
66 public boolean supportsRemove() {
67 return false;
68 }
69
70 @Test
71 public void testDecorateFactory() {
72 Iterator<E> it = makeObject();
73 assertSame(it, UnmodifiableIterator.unmodifiableIterator(it));
74
75 it = testList.iterator();
76 assertNotSame(it, UnmodifiableIterator.unmodifiableIterator(it));
77
78 assertThrows(NullPointerException.class, () -> UnmodifiableIterator.unmodifiableIterator(null));
79 }
80
81 @Test
82 public void testIterator() {
83 assertTrue(makeEmptyIterator() instanceof Unmodifiable);
84 }
85
86 }