1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.primitives.adapters;
18
19 import java.util.Iterator;
20 import java.util.ListIterator;
21 import java.util.NoSuchElementException;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 import org.apache.commons.collections.iterators.AbstractTestListIterator;
27 import org.apache.commons.collections.primitives.ArrayDoubleList;
28 import org.apache.commons.collections.primitives.DoubleList;
29
30
31
32
33
34 public class TestDoubleListIteratorListIterator extends AbstractTestListIterator {
35
36
37
38
39 public TestDoubleListIteratorListIterator(String testName) {
40 super(testName);
41 }
42
43 public static Test suite() {
44 return new TestSuite(TestDoubleListIteratorListIterator.class);
45 }
46
47
48
49
50 public ListIterator makeEmptyListIterator() {
51 return DoubleListIteratorListIterator.wrap(makeEmptyDoubleList().listIterator());
52 }
53
54 public ListIterator makeFullListIterator() {
55 return DoubleListIteratorListIterator.wrap(makeFullDoubleList().listIterator());
56 }
57
58 protected DoubleList makeEmptyDoubleList() {
59 return new ArrayDoubleList();
60 }
61
62 protected DoubleList makeFullDoubleList() {
63 DoubleList list = makeEmptyDoubleList();
64 double[] elts = getFullElements();
65 for(int i=0;i<elts.length;i++) {
66 list.add((double)elts[i]);
67 }
68 return list;
69 }
70
71 public double[] getFullElements() {
72 return new double[] { (double)0, (double)1, (double)2, (double)3, (double)4, (double)5, (double)6, (double)7, (double)8, (double)9 };
73 }
74
75 public Object addSetValue() {
76 return new Double((double)1);
77 }
78
79
80
81
82
83 public void testNextHasNextRemove() {
84 double[] elements = getFullElements();
85 Iterator iter = makeFullIterator();
86 for(int i=0;i<elements.length;i++) {
87 assertTrue(iter.hasNext());
88 assertEquals(new Double(elements[i]),iter.next());
89 if(supportsRemove()) {
90 iter.remove();
91 }
92 }
93 assertTrue(! iter.hasNext() );
94 }
95
96 public void testEmptyIterator() {
97 assertTrue( ! makeEmptyIterator().hasNext() );
98 try {
99 makeEmptyIterator().next();
100 fail("Expected NoSuchElementException");
101 } catch(NoSuchElementException e) {
102
103 }
104 if(supportsRemove()) {
105 try {
106 makeEmptyIterator().remove();
107 fail("Expected IllegalStateException");
108 } catch(IllegalStateException e) {
109
110 }
111 }
112 }
113
114 public void testRemoveBeforeNext() {
115 if(supportsRemove()) {
116 try {
117 makeFullIterator().remove();
118 fail("Expected IllegalStateException");
119 } catch(IllegalStateException e) {
120
121 }
122 }
123 }
124
125 public void testRemoveAfterRemove() {
126 if(supportsRemove()) {
127 Iterator iter = makeFullIterator();
128 iter.next();
129 iter.remove();
130 try {
131 iter.remove();
132 fail("Expected IllegalStateException");
133 } catch(IllegalStateException e) {
134
135 }
136 }
137 }
138
139 }