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.List;
28 import java.util.ListIterator;
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
38
39 public class UnmodifiableListIteratorTest<E> extends AbstractListIteratorTest<E> {
40
41 protected String[] testArray = {"One", "Two", "Three"};
42 protected List<E> testList;
43
44 @Override
45 public ListIterator<E> makeEmptyIterator() {
46 return UnmodifiableListIterator.unmodifiableListIterator(Collections.<E>emptyList().listIterator());
47 }
48
49 @Override
50 public ListIterator<E> makeObject() {
51 return UnmodifiableListIterator.unmodifiableListIterator(testList.listIterator());
52 }
53
54 @SuppressWarnings("unchecked")
55 @BeforeEach
56 protected void setUp() throws Exception {
57 testList = new ArrayList<>(Arrays.asList((E[]) testArray));
58 }
59
60 @Override
61 public boolean supportsAdd() {
62 return false;
63 }
64
65 @Override
66 public boolean supportsRemove() {
67 return false;
68 }
69
70 @Override
71 public boolean supportsSet() {
72 return false;
73 }
74
75 @Test
76 public void testDecorateFactory() {
77 ListIterator<E> it = makeObject();
78 assertSame(it, UnmodifiableListIterator.unmodifiableListIterator(it));
79
80 it = testList.listIterator();
81 assertNotSame(it, UnmodifiableListIterator.unmodifiableListIterator(it));
82
83 assertThrows(NullPointerException.class, () -> UnmodifiableListIterator.unmodifiableListIterator(null));
84 }
85
86 @Test
87 public void testListIterator() {
88 assertTrue(makeEmptyIterator() instanceof Unmodifiable);
89 }
90
91 }