OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 14 matching lines...) Expand all Loading... |
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 package com.google.protobuf; | 31 package com.google.protobuf; |
32 | 32 |
33 import static java.util.Arrays.asList; | 33 import static java.util.Arrays.asList; |
34 | 34 |
| 35 import junit.framework.TestCase; |
| 36 |
35 import java.util.Collections; | 37 import java.util.Collections; |
36 import java.util.ConcurrentModificationException; | 38 import java.util.ConcurrentModificationException; |
37 import java.util.Iterator; | 39 import java.util.Iterator; |
38 import junit.framework.TestCase; | |
39 | 40 |
40 /** | 41 /** |
41 * Tests for {@link LongArrayList}. | 42 * Tests for {@link LongArrayList}. |
42 * | 43 * |
43 * @author dweis@google.com (Daniel Weis) | 44 * @author dweis@google.com (Daniel Weis) |
44 */ | 45 */ |
45 public class LongArrayListTest extends TestCase { | 46 public class LongArrayListTest extends TestCase { |
46 | 47 |
47 private static final LongArrayList UNARY_LIST = | 48 private static final LongArrayList UNARY_LIST = newImmutableLongArrayList(1); |
48 newImmutableLongArrayList(1); | |
49 private static final LongArrayList TERTIARY_LIST = | 49 private static final LongArrayList TERTIARY_LIST = |
50 newImmutableLongArrayList(1, 2, 3); | 50 newImmutableLongArrayList(1, 2, 3); |
51 | 51 |
52 private LongArrayList list; | 52 private LongArrayList list; |
53 | 53 |
54 @Override | 54 @Override |
55 protected void setUp() throws Exception { | 55 protected void setUp() throws Exception { |
56 list = new LongArrayList(); | 56 list = new LongArrayList(); |
57 } | 57 } |
58 | 58 |
59 public void testEmptyListReturnsSameInstance() { | 59 public void testEmptyListReturnsSameInstance() { |
60 assertSame(LongArrayList.emptyList(), LongArrayList.emptyList()); | 60 assertSame(LongArrayList.emptyList(), LongArrayList.emptyList()); |
61 } | 61 } |
62 | 62 |
63 public void testEmptyListIsImmutable() { | 63 public void testEmptyListIsImmutable() { |
64 assertImmutable(LongArrayList.emptyList()); | 64 assertImmutable(LongArrayList.emptyList()); |
65 } | 65 } |
66 | 66 |
67 public void testMakeImmutable() { | 67 public void testMakeImmutable() { |
68 list.addLong(3); | 68 list.addLong(2); |
69 list.addLong(4); | 69 list.addLong(4); |
70 list.addLong(5); | 70 list.addLong(6); |
71 list.addLong(7); | 71 list.addLong(8); |
72 list.makeImmutable(); | 72 list.makeImmutable(); |
73 assertImmutable(list); | 73 assertImmutable(list); |
74 } | 74 } |
75 | 75 |
76 public void testModificationWithIteration() { | 76 public void testModificationWithIteration() { |
77 list.addAll(asList(1L, 2L, 3L, 4L)); | 77 list.addAll(asList(1L, 2L, 3L, 4L)); |
78 Iterator<Long> iterator = list.iterator(); | 78 Iterator<Long> iterator = list.iterator(); |
79 assertEquals(4, list.size()); | 79 assertEquals(4, list.size()); |
80 assertEquals(1L, (long) list.get(0)); | 80 assertEquals(1, (long) list.get(0)); |
81 assertEquals(1L, (long) iterator.next()); | 81 assertEquals(1, (long) iterator.next()); |
82 list.set(0, 1L); | 82 list.set(0, 1L); |
83 assertEquals(2L, (long) iterator.next()); | 83 assertEquals(2, (long) iterator.next()); |
84 | 84 |
85 list.remove(0); | 85 list.remove(0); |
86 try { | 86 try { |
87 iterator.next(); | 87 iterator.next(); |
88 fail(); | 88 fail(); |
89 } catch (ConcurrentModificationException e) { | 89 } catch (ConcurrentModificationException e) { |
90 // expected | 90 // expected |
91 } | 91 } |
92 | 92 |
93 iterator = list.iterator(); | 93 iterator = list.iterator(); |
94 list.add(0, 0L); | 94 list.add(0, 0L); |
95 try { | 95 try { |
96 iterator.next(); | 96 iterator.next(); |
97 fail(); | 97 fail(); |
98 } catch (ConcurrentModificationException e) { | 98 } catch (ConcurrentModificationException e) { |
99 // expected | 99 // expected |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 public void testGet() { | 103 public void testGet() { |
104 assertEquals(1L, (long) TERTIARY_LIST.get(0)); | 104 assertEquals(1, (long) TERTIARY_LIST.get(0)); |
105 assertEquals(2L, (long) TERTIARY_LIST.get(1)); | 105 assertEquals(2, (long) TERTIARY_LIST.get(1)); |
106 assertEquals(3L, (long) TERTIARY_LIST.get(2)); | 106 assertEquals(3, (long) TERTIARY_LIST.get(2)); |
107 | 107 |
108 try { | 108 try { |
109 TERTIARY_LIST.get(-1); | 109 TERTIARY_LIST.get(-1); |
110 fail(); | 110 fail(); |
111 } catch (IndexOutOfBoundsException e) { | 111 } catch (IndexOutOfBoundsException e) { |
112 // expected | 112 // expected |
113 } | 113 } |
114 | 114 |
115 try { | 115 try { |
116 TERTIARY_LIST.get(3); | 116 TERTIARY_LIST.get(3); |
117 fail(); | 117 fail(); |
118 } catch (IndexOutOfBoundsException e) { | 118 } catch (IndexOutOfBoundsException e) { |
119 // expected | 119 // expected |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 public void testGetLong() { | 123 public void testGetLong() { |
124 assertEquals(1L, TERTIARY_LIST.getLong(0)); | 124 assertEquals(1, TERTIARY_LIST.getLong(0)); |
125 assertEquals(2L, TERTIARY_LIST.getLong(1)); | 125 assertEquals(2, TERTIARY_LIST.getLong(1)); |
126 assertEquals(3L, TERTIARY_LIST.getLong(2)); | 126 assertEquals(3, TERTIARY_LIST.getLong(2)); |
127 | 127 |
128 try { | 128 try { |
129 TERTIARY_LIST.get(-1); | 129 TERTIARY_LIST.get(-1); |
130 fail(); | 130 fail(); |
131 } catch (IndexOutOfBoundsException e) { | 131 } catch (IndexOutOfBoundsException e) { |
132 // expected | 132 // expected |
133 } | 133 } |
134 | 134 |
135 try { | 135 try { |
136 TERTIARY_LIST.get(3); | 136 TERTIARY_LIST.get(3); |
137 fail(); | 137 fail(); |
138 } catch (IndexOutOfBoundsException e) { | 138 } catch (IndexOutOfBoundsException e) { |
139 // expected | 139 // expected |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 public void testSize() { | 143 public void testSize() { |
144 assertEquals(0, LongArrayList.emptyList().size()); | 144 assertEquals(0, LongArrayList.emptyList().size()); |
145 assertEquals(1, UNARY_LIST.size()); | 145 assertEquals(1, UNARY_LIST.size()); |
146 assertEquals(3, TERTIARY_LIST.size()); | 146 assertEquals(3, TERTIARY_LIST.size()); |
147 | 147 |
148 list.addLong(3); | 148 list.addLong(2); |
149 list.addLong(4); | 149 list.addLong(4); |
150 list.addLong(6); | 150 list.addLong(6); |
151 list.addLong(8); | 151 list.addLong(8); |
152 assertEquals(4, list.size()); | 152 assertEquals(4, list.size()); |
153 | 153 |
154 list.remove(0); | 154 list.remove(0); |
155 assertEquals(3, list.size()); | 155 assertEquals(3, list.size()); |
156 | 156 |
157 list.add(17L); | 157 list.add(16L); |
158 assertEquals(4, list.size()); | 158 assertEquals(4, list.size()); |
159 } | 159 } |
160 | 160 |
161 public void testSet() { | 161 public void testSet() { |
162 list.addLong(2); | 162 list.addLong(2); |
163 list.addLong(4); | 163 list.addLong(4); |
| 164 |
| 165 assertEquals(2, (long) list.set(0, 0L)); |
| 166 assertEquals(0, list.getLong(0)); |
164 | 167 |
165 assertEquals(2L, (long) list.set(0, 3L)); | 168 assertEquals(4, (long) list.set(1, 0L)); |
166 assertEquals(3L, list.getLong(0)); | 169 assertEquals(0, list.getLong(1)); |
167 | 170 |
168 assertEquals(4L, (long) list.set(1, 0L)); | |
169 assertEquals(0L, list.getLong(1)); | |
170 | |
171 try { | 171 try { |
172 list.set(-1, 0L); | 172 list.set(-1, 0L); |
173 fail(); | 173 fail(); |
174 } catch (IndexOutOfBoundsException e) { | 174 } catch (IndexOutOfBoundsException e) { |
175 // expected | 175 // expected |
176 } | 176 } |
177 | 177 |
178 try { | 178 try { |
179 list.set(2, 0L); | 179 list.set(2, 0L); |
180 fail(); | 180 fail(); |
181 } catch (IndexOutOfBoundsException e) { | 181 } catch (IndexOutOfBoundsException e) { |
182 // expected | 182 // expected |
183 } | 183 } |
184 } | 184 } |
| 185 |
| 186 public void testSetLong() { |
| 187 list.addLong(2); |
| 188 list.addLong(4); |
| 189 |
| 190 assertEquals(2, list.setLong(0, 0)); |
| 191 assertEquals(0, list.getLong(0)); |
185 | 192 |
186 public void testSetLong() { | 193 assertEquals(4, list.setLong(1, 0)); |
187 list.addLong(1); | 194 assertEquals(0, list.getLong(1)); |
188 list.addLong(3); | 195 |
189 | |
190 assertEquals(1L, list.setLong(0, 0)); | |
191 assertEquals(0L, list.getLong(0)); | |
192 | |
193 assertEquals(3L, list.setLong(1, 0)); | |
194 assertEquals(0L, list.getLong(1)); | |
195 | |
196 try { | 196 try { |
197 list.setLong(-1, 0); | 197 list.setLong(-1, 0); |
198 fail(); | 198 fail(); |
199 } catch (IndexOutOfBoundsException e) { | 199 } catch (IndexOutOfBoundsException e) { |
200 // expected | 200 // expected |
201 } | 201 } |
202 | 202 |
203 try { | 203 try { |
204 list.setLong(2, 0); | 204 list.setLong(2, 0); |
205 fail(); | 205 fail(); |
206 } catch (IndexOutOfBoundsException e) { | 206 } catch (IndexOutOfBoundsException e) { |
207 // expected | 207 // expected |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 public void testAdd() { | 211 public void testAdd() { |
212 assertEquals(0, list.size()); | 212 assertEquals(0, list.size()); |
213 | 213 |
214 assertTrue(list.add(2L)); | 214 assertTrue(list.add(2L)); |
215 assertEquals(asList(2L), list); | 215 assertEquals(asList(2L), list); |
216 | 216 |
217 assertTrue(list.add(3L)); | 217 assertTrue(list.add(3L)); |
218 list.add(0, 4L); | 218 list.add(0, 4L); |
219 assertEquals(asList(4L, 2L, 3L), list); | 219 assertEquals(asList(4L, 2L, 3L), list); |
220 | 220 |
221 list.add(0, 1L); | 221 list.add(0, 1L); |
222 list.add(0, 0L); | 222 list.add(0, 0L); |
223 // Force a resize by getting up to 11 elements. | 223 // Force a resize by getting up to 11 elements. |
224 for (int i = 0; i < 6; i++) { | 224 for (int i = 0; i < 6; i++) { |
225 list.add(Long.valueOf(5 + i)); | 225 list.add(Long.valueOf(5 + i)); |
226 } | 226 } |
227 assertEquals( | 227 assertEquals(asList(0L, 1L, 4L, 2L, 3L, 5L, 6L, 7L, 8L, 9L, 10L), list); |
228 asList(0L, 1L, 4L, 2L, 3L, 5L, 6L, 7L, 8L, 9L, 10L), | 228 |
229 list); | |
230 | |
231 try { | 229 try { |
232 list.add(-1, 5L); | 230 list.add(-1, 5L); |
233 } catch (IndexOutOfBoundsException e) { | 231 } catch (IndexOutOfBoundsException e) { |
234 // expected | 232 // expected |
235 } | 233 } |
236 | 234 |
237 try { | 235 try { |
238 list.add(4, 5L); | 236 list.add(4, 5L); |
239 } catch (IndexOutOfBoundsException e) { | 237 } catch (IndexOutOfBoundsException e) { |
240 // expected | 238 // expected |
241 } | 239 } |
242 } | 240 } |
243 | 241 |
244 public void testAddLong() { | 242 public void testAddLong() { |
245 assertEquals(0, list.size()); | 243 assertEquals(0, list.size()); |
246 | 244 |
247 list.addLong(2); | 245 list.addLong(2); |
248 assertEquals(asList(2L), list); | 246 assertEquals(asList(2L), list); |
249 | 247 |
250 list.addLong(3); | 248 list.addLong(3); |
251 assertEquals(asList(2L, 3L), list); | 249 assertEquals(asList(2L, 3L), list); |
252 } | 250 } |
253 | 251 |
254 public void testAddAll() { | 252 public void testAddAll() { |
255 assertEquals(0, list.size()); | 253 assertEquals(0, list.size()); |
256 | 254 |
257 assertTrue(list.addAll(Collections.singleton(1L))); | 255 assertTrue(list.addAll(Collections.singleton(1L))); |
258 assertEquals(1, list.size()); | 256 assertEquals(1, list.size()); |
259 assertEquals(1L, (long) list.get(0)); | 257 assertEquals(1, (long) list.get(0)); |
260 assertEquals(1L, list.getLong(0)); | 258 assertEquals(1, list.getLong(0)); |
261 | 259 |
262 assertTrue(list.addAll(asList(2L, 3L, 4L, 5L, 6L))); | 260 assertTrue(list.addAll(asList(2L, 3L, 4L, 5L, 6L))); |
263 assertEquals(asList(1L, 2L, 3L, 4L, 5L, 6L), list); | 261 assertEquals(asList(1L, 2L, 3L, 4L, 5L, 6L), list); |
264 | 262 |
265 assertTrue(list.addAll(TERTIARY_LIST)); | 263 assertTrue(list.addAll(TERTIARY_LIST)); |
266 assertEquals(asList(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L), list); | 264 assertEquals(asList(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L), list); |
267 | 265 |
268 assertFalse(list.addAll(Collections.<Long>emptyList())); | 266 assertFalse(list.addAll(Collections.<Long>emptyList())); |
269 assertFalse(list.addAll(LongArrayList.emptyList())); | 267 assertFalse(list.addAll(LongArrayList.emptyList())); |
270 } | 268 } |
271 | 269 |
272 public void testRemove() { | 270 public void testRemove() { |
273 list.addAll(TERTIARY_LIST); | 271 list.addAll(TERTIARY_LIST); |
274 assertEquals(1L, (long) list.remove(0)); | 272 assertEquals(1, (long) list.remove(0)); |
275 assertEquals(asList(2L, 3L), list); | 273 assertEquals(asList(2L, 3L), list); |
276 | 274 |
277 assertTrue(list.remove(Long.valueOf(3))); | 275 assertTrue(list.remove(3L)); |
278 assertEquals(asList(2L), list); | 276 assertEquals(asList(2L), list); |
279 | 277 |
280 assertFalse(list.remove(Long.valueOf(3))); | 278 assertFalse(list.remove(3L)); |
281 assertEquals(asList(2L), list); | 279 assertEquals(asList(2L), list); |
282 | 280 |
283 assertEquals(2L, (long) list.remove(0)); | 281 assertEquals(2, (long) list.remove(0)); |
284 assertEquals(asList(), list); | 282 assertEquals(asList(), list); |
285 | 283 |
286 try { | 284 try { |
287 list.remove(-1); | 285 list.remove(-1); |
288 fail(); | 286 fail(); |
289 } catch (IndexOutOfBoundsException e) { | 287 } catch (IndexOutOfBoundsException e) { |
290 // expected | 288 // expected |
291 } | 289 } |
292 | 290 |
293 try { | 291 try { |
294 list.remove(0); | 292 list.remove(0); |
295 } catch (IndexOutOfBoundsException e) { | 293 } catch (IndexOutOfBoundsException e) { |
296 // expected | 294 // expected |
297 } | 295 } |
298 } | 296 } |
299 | 297 |
300 private void assertImmutable(LongArrayList list) { | 298 private void assertImmutable(LongArrayList list) { |
301 if (list.contains(1L)) { | 299 if (list.contains(1L)) { |
302 throw new RuntimeException("Cannot test the immutability of lists that con
tain 1."); | 300 throw new RuntimeException("Cannot test the immutability of lists that con
tain 1."); |
303 } | 301 } |
304 | 302 |
305 try { | 303 try { |
306 list.add(1L); | 304 list.add(1L); |
307 fail(); | 305 fail(); |
308 } catch (UnsupportedOperationException e) { | 306 } catch (UnsupportedOperationException e) { |
309 // expected | 307 // expected |
310 } | 308 } |
311 | 309 |
312 try { | 310 try { |
313 list.add(0, 1L); | 311 list.add(0, 1L); |
314 fail(); | 312 fail(); |
315 } catch (UnsupportedOperationException e) { | 313 } catch (UnsupportedOperationException e) { |
316 // expected | 314 // expected |
317 } | 315 } |
318 | 316 |
319 try { | 317 try { |
320 list.addAll(Collections.<Long>emptyList()); | 318 list.addAll(Collections.<Long>emptyList()); |
321 fail(); | 319 fail(); |
322 } catch (UnsupportedOperationException e) { | 320 } catch (UnsupportedOperationException e) { |
323 // expected | 321 // expected |
324 } | 322 } |
325 | 323 |
326 try { | 324 try { |
327 list.addAll(Collections.singletonList(1L)); | 325 list.addAll(Collections.singletonList(1L)); |
328 fail(); | 326 fail(); |
329 } catch (UnsupportedOperationException e) { | 327 } catch (UnsupportedOperationException e) { |
330 // expected | 328 // expected |
331 } | 329 } |
332 | 330 |
333 try { | 331 try { |
334 list.addAll(new LongArrayList()); | 332 list.addAll(new LongArrayList()); |
335 fail(); | 333 fail(); |
336 } catch (UnsupportedOperationException e) { | 334 } catch (UnsupportedOperationException e) { |
337 // expected | 335 // expected |
338 } | 336 } |
339 | 337 |
340 try { | 338 try { |
341 list.addAll(UNARY_LIST); | 339 list.addAll(UNARY_LIST); |
342 fail(); | 340 fail(); |
343 } catch (UnsupportedOperationException e) { | 341 } catch (UnsupportedOperationException e) { |
344 // expected | 342 // expected |
345 } | 343 } |
346 | 344 |
347 try { | 345 try { |
348 list.addAll(0, Collections.singleton(1L)); | 346 list.addAll(0, Collections.singleton(1L)); |
349 fail(); | 347 fail(); |
350 } catch (UnsupportedOperationException e) { | 348 } catch (UnsupportedOperationException e) { |
351 // expected | 349 // expected |
352 } | 350 } |
353 | 351 |
354 try { | 352 try { |
355 list.addAll(0, UNARY_LIST); | 353 list.addAll(0, UNARY_LIST); |
356 fail(); | 354 fail(); |
357 } catch (UnsupportedOperationException e) { | 355 } catch (UnsupportedOperationException e) { |
358 // expected | 356 // expected |
359 } | 357 } |
360 | 358 |
361 try { | 359 try { |
362 list.addAll(0, Collections.<Long>emptyList()); | 360 list.addAll(0, Collections.<Long>emptyList()); |
363 fail(); | 361 fail(); |
364 } catch (UnsupportedOperationException e) { | 362 } catch (UnsupportedOperationException e) { |
365 // expected | 363 // expected |
366 } | 364 } |
367 | 365 |
368 try { | 366 try { |
369 list.addLong(0); | 367 list.addLong(0); |
370 fail(); | 368 fail(); |
371 } catch (UnsupportedOperationException e) { | 369 } catch (UnsupportedOperationException e) { |
372 // expected | 370 // expected |
373 } | 371 } |
374 | 372 |
375 try { | 373 try { |
376 list.clear(); | 374 list.clear(); |
377 fail(); | 375 fail(); |
378 } catch (UnsupportedOperationException e) { | 376 } catch (UnsupportedOperationException e) { |
379 // expected | 377 // expected |
380 } | 378 } |
381 | 379 |
382 try { | 380 try { |
383 list.remove(1); | 381 list.remove(1); |
384 fail(); | 382 fail(); |
385 } catch (UnsupportedOperationException e) { | 383 } catch (UnsupportedOperationException e) { |
386 // expected | 384 // expected |
387 } | 385 } |
388 | 386 |
389 try { | 387 try { |
390 list.remove(new Object()); | 388 list.remove(new Object()); |
391 fail(); | 389 fail(); |
392 } catch (UnsupportedOperationException e) { | 390 } catch (UnsupportedOperationException e) { |
393 // expected | 391 // expected |
394 } | 392 } |
395 | 393 |
396 try { | 394 try { |
397 list.removeAll(Collections.<Long>emptyList()); | 395 list.removeAll(Collections.<Long>emptyList()); |
398 fail(); | 396 fail(); |
399 } catch (UnsupportedOperationException e) { | 397 } catch (UnsupportedOperationException e) { |
400 // expected | 398 // expected |
401 } | 399 } |
402 | 400 |
403 try { | 401 try { |
404 list.removeAll(Collections.singleton(1L)); | 402 list.removeAll(Collections.singleton(1L)); |
405 fail(); | 403 fail(); |
406 } catch (UnsupportedOperationException e) { | 404 } catch (UnsupportedOperationException e) { |
407 // expected | 405 // expected |
408 } | 406 } |
409 | 407 |
410 try { | 408 try { |
411 list.removeAll(UNARY_LIST); | 409 list.removeAll(UNARY_LIST); |
412 fail(); | 410 fail(); |
413 } catch (UnsupportedOperationException e) { | 411 } catch (UnsupportedOperationException e) { |
414 // expected | 412 // expected |
415 } | 413 } |
416 | 414 |
417 try { | 415 try { |
418 list.retainAll(Collections.<Long>emptyList()); | 416 list.retainAll(Collections.<Long>emptyList()); |
419 fail(); | 417 fail(); |
420 } catch (UnsupportedOperationException e) { | 418 } catch (UnsupportedOperationException e) { |
421 // expected | 419 // expected |
422 } | 420 } |
423 | 421 |
424 try { | 422 try { |
425 list.retainAll(Collections.singleton(1L)); | 423 list.retainAll(Collections.singleton(1L)); |
426 fail(); | 424 fail(); |
427 } catch (UnsupportedOperationException e) { | 425 } catch (UnsupportedOperationException e) { |
428 // expected | 426 // expected |
429 } | 427 } |
430 | 428 |
431 try { | 429 try { |
432 list.retainAll(UNARY_LIST); | 430 list.retainAll(UNARY_LIST); |
433 fail(); | 431 fail(); |
434 } catch (UnsupportedOperationException e) { | 432 } catch (UnsupportedOperationException e) { |
435 // expected | 433 // expected |
436 } | 434 } |
437 | 435 |
438 try { | 436 try { |
439 list.set(0, 0L); | 437 list.set(0, 0L); |
440 fail(); | 438 fail(); |
441 } catch (UnsupportedOperationException e) { | 439 } catch (UnsupportedOperationException e) { |
442 // expected | 440 // expected |
443 } | 441 } |
444 | 442 |
445 try { | 443 try { |
446 list.setLong(0, 0); | 444 list.setLong(0, 0); |
447 fail(); | 445 fail(); |
448 } catch (UnsupportedOperationException e) { | 446 } catch (UnsupportedOperationException e) { |
449 // expected | 447 // expected |
450 } | 448 } |
451 } | 449 } |
452 | 450 |
453 private static LongArrayList newImmutableLongArrayList(long... elements) { | 451 private static LongArrayList newImmutableLongArrayList(long... elements) { |
454 LongArrayList list = new LongArrayList(); | 452 LongArrayList list = new LongArrayList(); |
455 for (long element : elements) { | 453 for (long element : elements) { |
456 list.addLong(element); | 454 list.addLong(element); |
457 } | 455 } |
458 list.makeImmutable(); | 456 list.makeImmutable(); |
459 return list; | 457 return list; |
460 } | 458 } |
461 } | 459 } |
OLD | NEW |