1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertNotSame; |
25 |
|
import static org.testng.Assert.fail; |
26 |
|
|
27 |
|
import java.util.ArrayList; |
28 |
|
import java.util.ConcurrentModificationException; |
29 |
|
import java.util.List; |
30 |
|
|
31 |
|
import org.testng.annotations.BeforeMethod; |
32 |
|
import org.testng.annotations.Test; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 0% |
Uncovered Elements: 90 (90) |
Complexity: 18 |
Complexity Density: 0.28 |
|
39 |
|
public class ConcurrentModificationTest |
40 |
|
{ |
41 |
|
static int MAX = 10; |
42 |
|
|
43 |
|
int[] intArray; |
44 |
|
|
45 |
|
List<Integer> intList; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
50 |
0 |
@BeforeMethod()... |
51 |
|
public void setUp() |
52 |
|
{ |
53 |
0 |
intArray = new int[MAX]; |
54 |
0 |
intList = new ArrayList<Integer>(); |
55 |
0 |
for (int i = 0; i < MAX; i++) |
56 |
|
{ |
57 |
0 |
intArray[i] = i; |
58 |
0 |
intList.add(i); |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4-
|
|
65 |
0 |
@Test... |
66 |
|
public void test_nullCase() |
67 |
|
{ |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
0 |
int j = 0; |
72 |
0 |
for (int i : intArray) |
73 |
|
{ |
74 |
0 |
assertEquals(i, j); |
75 |
0 |
j++; |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
0 |
j = 0; |
82 |
0 |
for (int i : intList) |
83 |
|
{ |
84 |
0 |
assertEquals(i, j); |
85 |
0 |
j++; |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
4-
|
|
93 |
0 |
@Test... |
94 |
|
public void testEnhancedForLoop_arrayExtended() |
95 |
|
{ |
96 |
0 |
int j = 0; |
97 |
0 |
for (int i : intArray) |
98 |
|
{ |
99 |
0 |
if (j == 5) |
100 |
|
{ |
101 |
0 |
intArray = new int[MAX + 1]; |
102 |
|
} |
103 |
0 |
assertEquals(i, j); |
104 |
0 |
j++; |
105 |
|
} |
106 |
0 |
assertEquals(j, MAX); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
4-
|
|
113 |
0 |
@Test... |
114 |
|
public void testEnhancedForLoop_arrayNulled() |
115 |
|
{ |
116 |
0 |
int j = 0; |
117 |
0 |
for (int i : intArray) |
118 |
|
{ |
119 |
0 |
if (j == 5) |
120 |
|
{ |
121 |
0 |
intArray = null; |
122 |
|
} |
123 |
0 |
assertEquals(i, j); |
124 |
0 |
j++; |
125 |
|
} |
126 |
0 |
assertEquals(j, MAX); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
4-
|
|
137 |
0 |
@Test... |
138 |
|
public void testEnhancedForLoop_arrayModified() |
139 |
|
{ |
140 |
0 |
int j = 0; |
141 |
0 |
for (int i : intArray) |
142 |
|
{ |
143 |
0 |
if (j == 5) |
144 |
|
{ |
145 |
0 |
intArray[5] = -1; |
146 |
0 |
intArray[6] = -2; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
0 |
int expected = j == 6 ? -2 : j; |
153 |
0 |
assertEquals(i, expected); |
154 |
0 |
j++; |
155 |
|
} |
156 |
0 |
assertEquals(j, MAX); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
4-
|
|
162 |
0 |
@Test... |
163 |
|
public void testEnhancedForLoop_listExtended() |
164 |
|
{ |
165 |
0 |
int j = 0; |
166 |
0 |
try |
167 |
|
{ |
168 |
0 |
for (int i : intList) |
169 |
|
{ |
170 |
0 |
if (j == 5) |
171 |
|
{ |
172 |
0 |
intList.add(MAX + 1); |
173 |
|
} |
174 |
0 |
assertEquals(i, j); |
175 |
0 |
j++; |
176 |
|
} |
177 |
|
} catch (ConcurrentModificationException e) |
178 |
|
{ |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
0 |
assertEquals(j, 6); |
184 |
0 |
return; |
185 |
|
} |
186 |
0 |
fail("Expected exception"); |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
4-
|
|
193 |
0 |
@Test... |
194 |
|
public void testEnhancedForLoop_listModified() |
195 |
|
{ |
196 |
0 |
int j = 0; |
197 |
0 |
for (int i : intList) |
198 |
|
{ |
199 |
0 |
if (j == 5) |
200 |
|
{ |
201 |
0 |
intList.set(5, -1); |
202 |
0 |
intList.set(6, -2); |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
0 |
int expected = j == 6 ? -2 : j; |
210 |
0 |
assertEquals(i, expected); |
211 |
0 |
j++; |
212 |
|
} |
213 |
0 |
assertEquals(j, MAX); |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
4-
|
|
219 |
0 |
@Test... |
220 |
|
public void testEnhancedForLoop_listRenewed() |
221 |
|
{ |
222 |
0 |
Object theList = intList; |
223 |
0 |
int j = 0; |
224 |
0 |
for (int i : intList) |
225 |
|
{ |
226 |
0 |
if (j == 5) |
227 |
|
{ |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
0 |
setUp(); |
232 |
0 |
assertNotSame(theList, intList); |
233 |
|
} |
234 |
0 |
assertEquals(i, j); |
235 |
0 |
j++; |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
0 |
assertEquals(j, MAX); |
243 |
|
} |
244 |
|
} |