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 BooleanArrayList}. | 42 * Tests for {@link BooleanArrayList}. |
42 * | 43 * |
43 * @author dweis@google.com (Daniel Weis) | 44 * @author dweis@google.com (Daniel Weis) |
44 */ | 45 */ |
45 public class BooleanArrayListTest extends TestCase { | 46 public class BooleanArrayListTest extends TestCase { |
46 | 47 |
47 private static final BooleanArrayList UNARY_LIST = | 48 private static final BooleanArrayList UNARY_LIST = newImmutableBooleanArrayLis
t(true); |
48 newImmutableBooleanArrayList(true); | |
49 private static final BooleanArrayList TERTIARY_LIST = | 49 private static final BooleanArrayList TERTIARY_LIST = |
50 newImmutableBooleanArrayList(true, false, true); | 50 newImmutableBooleanArrayList(true, true, false); |
51 | 51 |
52 private BooleanArrayList list; | 52 private BooleanArrayList list; |
53 | 53 |
54 @Override | 54 @Override |
55 protected void setUp() throws Exception { | 55 protected void setUp() throws Exception { |
56 list = new BooleanArrayList(); | 56 list = new BooleanArrayList(); |
57 } | 57 } |
58 | 58 |
59 public void testEmptyListReturnsSameInstance() { | 59 public void testEmptyListReturnsSameInstance() { |
60 assertSame(BooleanArrayList.emptyList(), BooleanArrayList.emptyList()); | 60 assertSame(BooleanArrayList.emptyList(), BooleanArrayList.emptyList()); |
61 } | 61 } |
62 | 62 |
63 public void testEmptyListIsImmutable() { | 63 public void testEmptyListIsImmutable() { |
64 assertImmutable(BooleanArrayList.emptyList()); | 64 assertImmutable(BooleanArrayList.emptyList()); |
65 } | 65 } |
66 | 66 |
67 public void testMakeImmutable() { | 67 public void testMakeImmutable() { |
68 list.addBoolean(true); | 68 list.addBoolean(true); |
69 list.addBoolean(false); | 69 list.addBoolean(false); |
70 list.addBoolean(true); | 70 list.addBoolean(true); |
71 list.addBoolean(true); | 71 list.addBoolean(true); |
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(true, false, true, false)); | 77 list.addAll(asList(true, false, false, true)); |
78 Iterator<Boolean> iterator = list.iterator(); | 78 Iterator<Boolean> iterator = list.iterator(); |
79 assertEquals(4, list.size()); | 79 assertEquals(4, list.size()); |
80 assertEquals(true, (boolean) list.get(0)); | 80 assertEquals(true, (boolean) list.get(0)); |
81 assertEquals(true, (boolean) iterator.next()); | 81 assertEquals(true, (boolean) iterator.next()); |
82 list.set(0, true); | 82 list.set(0, true); |
83 assertEquals(false, (boolean) iterator.next()); | 83 assertEquals(false, (boolean) 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, false); | 94 list.add(0, false); |
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(true, (boolean) TERTIARY_LIST.get(0)); | 104 assertEquals(true, (boolean) TERTIARY_LIST.get(0)); |
105 assertEquals(false, (boolean) TERTIARY_LIST.get(1)); | 105 assertEquals(true, (boolean) TERTIARY_LIST.get(1)); |
106 assertEquals(true, (boolean) TERTIARY_LIST.get(2)); | 106 assertEquals(false, (boolean) 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 testGetBoolean() { | 123 public void testGetInt() { |
124 assertEquals(true, TERTIARY_LIST.getBoolean(0)); | 124 assertEquals(true, TERTIARY_LIST.getBoolean(0)); |
125 assertEquals(false, TERTIARY_LIST.getBoolean(1)); | 125 assertEquals(true, TERTIARY_LIST.getBoolean(1)); |
126 assertEquals(true, TERTIARY_LIST.getBoolean(2)); | 126 assertEquals(false, TERTIARY_LIST.getBoolean(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, BooleanArrayList.emptyList().size()); | 144 assertEquals(0, BooleanArrayList.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.addBoolean(true); | 148 list.addBoolean(true); |
149 list.addBoolean(false); | 149 list.addBoolean(false); |
150 list.addBoolean(false); | 150 list.addBoolean(false); |
151 list.addBoolean(false); | 151 list.addBoolean(false); |
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(true); | 157 list.add(true); |
158 assertEquals(4, list.size()); | 158 assertEquals(4, list.size()); |
159 } | 159 } |
160 | 160 |
161 public void testSet() { | 161 public void testSet() { |
162 list.addBoolean(false); | 162 list.addBoolean(false); |
163 list.addBoolean(false); | 163 list.addBoolean(false); |
164 | 164 |
165 assertEquals(false, (boolean) list.set(0, true)); | 165 assertEquals(false, (boolean) list.set(0, true)); |
166 assertEquals(true, list.getBoolean(0)); | 166 assertEquals(true, list.getBoolean(0)); |
167 | 167 |
168 assertEquals(false, (boolean) list.set(1, false)); | 168 assertEquals(false, (boolean) list.set(1, false)); |
169 assertEquals(false, list.getBoolean(1)); | 169 assertEquals(false, list.getBoolean(1)); |
170 | 170 |
171 try { | 171 try { |
172 list.set(-1, false); | 172 list.set(-1, true); |
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, false); | 179 list.set(2, false); |
180 fail(); | 180 fail(); |
181 } catch (IndexOutOfBoundsException e) { | 181 } catch (IndexOutOfBoundsException e) { |
182 // expected | 182 // expected |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 public void testSetBoolean() { | 186 public void testSetInt() { |
187 list.addBoolean(true); | 187 list.addBoolean(true); |
188 list.addBoolean(true); | 188 list.addBoolean(true); |
189 | 189 |
190 assertEquals(true, list.setBoolean(0, false)); | 190 assertEquals(true, list.setBoolean(0, false)); |
191 assertEquals(false, list.getBoolean(0)); | 191 assertEquals(false, list.getBoolean(0)); |
192 | 192 |
193 assertEquals(true, list.setBoolean(1, false)); | 193 assertEquals(true, list.setBoolean(1, false)); |
194 assertEquals(false, list.getBoolean(1)); | 194 assertEquals(false, list.getBoolean(1)); |
195 | 195 |
196 try { | 196 try { |
197 list.setBoolean(-1, false); | 197 list.setBoolean(-1, false); |
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.setBoolean(2, false); | 204 list.setBoolean(2, true); |
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(true)); |
| 215 assertEquals(asList(true), list); |
| 216 |
214 assertTrue(list.add(false)); | 217 assertTrue(list.add(false)); |
215 assertEquals(asList(false), list); | |
216 | |
217 assertTrue(list.add(true)); | |
218 list.add(0, false); | 218 list.add(0, false); |
219 assertEquals(asList(false, false, true), list); | 219 assertEquals(asList(false, true, false), list); |
220 | 220 |
| 221 list.add(0, false); |
221 list.add(0, true); | 222 list.add(0, true); |
222 list.add(0, false); | |
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(i % 2 == 0); | 225 list.add(true); |
226 } | 226 } |
227 assertEquals( | 227 assertEquals(asList(true, false, false, true, false, true, true, true, true,
true, true), list); |
228 asList(false, true, false, false, true, true, false, true, false, true,
false), | 228 |
229 list); | |
230 | |
231 try { | 229 try { |
232 list.add(-1, true); | 230 list.add(-1, false); |
233 } catch (IndexOutOfBoundsException e) { | 231 } catch (IndexOutOfBoundsException e) { |
234 // expected | 232 // expected |
235 } | 233 } |
236 | 234 |
237 try { | 235 try { |
238 list.add(4, true); | 236 list.add(4, true); |
239 } catch (IndexOutOfBoundsException e) { | 237 } catch (IndexOutOfBoundsException e) { |
240 // expected | 238 // expected |
241 } | 239 } |
242 } | 240 } |
243 | 241 |
244 public void testAddBoolean() { | 242 public void testAddInt() { |
245 assertEquals(0, list.size()); | 243 assertEquals(0, list.size()); |
246 | 244 |
| 245 list.addBoolean(true); |
| 246 assertEquals(asList(true), list); |
| 247 |
247 list.addBoolean(false); | 248 list.addBoolean(false); |
248 assertEquals(asList(false), list); | 249 assertEquals(asList(true, false), list); |
249 | |
250 list.addBoolean(true); | |
251 assertEquals(asList(false, true), 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(true))); | 255 assertTrue(list.addAll(Collections.singleton(false))); |
258 assertEquals(1, list.size()); | 256 assertEquals(1, list.size()); |
259 assertEquals(true, (boolean) list.get(0)); | 257 assertEquals(false, (boolean) list.get(0)); |
260 assertEquals(true, list.getBoolean(0)); | 258 assertEquals(false, list.getBoolean(0)); |
261 | 259 |
262 assertTrue(list.addAll(asList(false, true, false, true, false))); | 260 assertTrue(list.addAll(asList(true, false, false, false, true))); |
263 assertEquals(asList(true, false, true, false, true, false), list); | 261 assertEquals(asList(false, true, false, false, false, true), list); |
264 | 262 |
265 assertTrue(list.addAll(TERTIARY_LIST)); | 263 assertTrue(list.addAll(TERTIARY_LIST)); |
266 assertEquals(asList(true, false, true, false, true, false, true, false, true
), list); | 264 assertEquals(asList(false, true, false, false, false, true, true, true, fals
e), list); |
267 | 265 |
268 assertFalse(list.addAll(Collections.<Boolean>emptyList())); | 266 assertFalse(list.addAll(Collections.<Boolean>emptyList())); |
269 assertFalse(list.addAll(BooleanArrayList.emptyList())); | 267 assertFalse(list.addAll(BooleanArrayList.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(true, (boolean) list.remove(0)); | 272 assertEquals(true, (boolean) list.remove(0)); |
275 assertEquals(asList(false, true), list); | 273 assertEquals(asList(true, false), list); |
276 | 274 |
277 assertTrue(list.remove(Boolean.TRUE)); | 275 assertTrue(list.remove(Boolean.TRUE)); |
278 assertEquals(asList(false), list); | 276 assertEquals(asList(false), list); |
279 | 277 |
280 assertFalse(list.remove(Boolean.TRUE)); | 278 assertFalse(list.remove(Boolean.TRUE)); |
281 assertEquals(asList(false), list); | 279 assertEquals(asList(false), list); |
282 | 280 |
283 assertEquals(false, (boolean) list.remove(0)); | 281 assertEquals(false, (boolean) 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(BooleanArrayList list) { | 298 private void assertImmutable(BooleanArrayList list) { |
301 | |
302 try { | 299 try { |
303 list.add(true); | 300 list.add(false); |
304 fail(); | 301 fail(); |
305 } catch (UnsupportedOperationException e) { | 302 } catch (UnsupportedOperationException e) { |
306 // expected | 303 // expected |
307 } | 304 } |
308 | 305 |
309 try { | 306 try { |
310 list.add(0, true); | 307 list.add(0, true); |
311 fail(); | 308 fail(); |
312 } catch (UnsupportedOperationException e) { | 309 } catch (UnsupportedOperationException e) { |
313 // expected | 310 // expected |
314 } | 311 } |
315 | 312 |
316 try { | 313 try { |
317 list.addAll(Collections.<Boolean>emptyList()); | 314 list.addAll(Collections.<Boolean>emptyList()); |
318 fail(); | 315 fail(); |
319 } catch (UnsupportedOperationException e) { | 316 } catch (UnsupportedOperationException e) { |
320 // expected | 317 // expected |
321 } | 318 } |
322 | 319 |
323 try { | 320 try { |
324 list.addAll(Collections.singletonList(true)); | 321 list.addAll(Collections.singletonList(false)); |
325 fail(); | 322 fail(); |
326 } catch (UnsupportedOperationException e) { | 323 } catch (UnsupportedOperationException e) { |
327 // expected | 324 // expected |
328 } | 325 } |
329 | 326 |
330 try { | 327 try { |
331 list.addAll(new BooleanArrayList()); | 328 list.addAll(new BooleanArrayList()); |
332 fail(); | 329 fail(); |
333 } catch (UnsupportedOperationException e) { | 330 } catch (UnsupportedOperationException e) { |
334 // expected | 331 // expected |
335 } | 332 } |
336 | 333 |
337 try { | 334 try { |
338 list.addAll(UNARY_LIST); | 335 list.addAll(UNARY_LIST); |
339 fail(); | 336 fail(); |
340 } catch (UnsupportedOperationException e) { | 337 } catch (UnsupportedOperationException e) { |
341 // expected | 338 // expected |
342 } | 339 } |
343 | 340 |
344 try { | 341 try { |
345 list.addAll(0, Collections.singleton(true)); | 342 list.addAll(0, Collections.singleton(true)); |
346 fail(); | 343 fail(); |
347 } catch (UnsupportedOperationException e) { | 344 } catch (UnsupportedOperationException e) { |
348 // expected | 345 // expected |
349 } | 346 } |
350 | 347 |
351 try { | 348 try { |
352 list.addAll(0, UNARY_LIST); | 349 list.addAll(0, UNARY_LIST); |
353 fail(); | 350 fail(); |
354 } catch (UnsupportedOperationException e) { | 351 } catch (UnsupportedOperationException e) { |
355 // expected | 352 // expected |
356 } | 353 } |
357 | 354 |
358 try { | 355 try { |
359 list.addAll(0, Collections.<Boolean>emptyList()); | 356 list.addAll(0, Collections.<Boolean>emptyList()); |
360 fail(); | 357 fail(); |
361 } catch (UnsupportedOperationException e) { | 358 } catch (UnsupportedOperationException e) { |
362 // expected | 359 // expected |
363 } | 360 } |
364 | 361 |
365 try { | 362 try { |
366 list.addBoolean(false); | 363 list.addBoolean(true); |
367 fail(); | 364 fail(); |
368 } catch (UnsupportedOperationException e) { | 365 } catch (UnsupportedOperationException e) { |
369 // expected | 366 // expected |
370 } | 367 } |
371 | 368 |
372 try { | 369 try { |
373 list.clear(); | 370 list.clear(); |
374 fail(); | 371 fail(); |
375 } catch (UnsupportedOperationException e) { | 372 } catch (UnsupportedOperationException e) { |
376 // expected | 373 // expected |
377 } | 374 } |
378 | 375 |
379 try { | 376 try { |
380 list.remove(1); | 377 list.remove(1); |
381 fail(); | 378 fail(); |
382 } catch (UnsupportedOperationException e) { | 379 } catch (UnsupportedOperationException e) { |
383 // expected | 380 // expected |
384 } | 381 } |
385 | 382 |
386 try { | 383 try { |
387 list.remove(new Object()); | 384 list.remove(new Object()); |
388 fail(); | 385 fail(); |
389 } catch (UnsupportedOperationException e) { | 386 } catch (UnsupportedOperationException e) { |
390 // expected | 387 // expected |
391 } | 388 } |
392 | 389 |
393 try { | 390 try { |
394 list.removeAll(Collections.<Boolean>emptyList()); | 391 list.removeAll(Collections.<Boolean>emptyList()); |
395 fail(); | 392 fail(); |
396 } catch (UnsupportedOperationException e) { | 393 } catch (UnsupportedOperationException e) { |
397 // expected | 394 // expected |
398 } | 395 } |
399 | 396 |
400 try { | 397 try { |
401 list.removeAll(Collections.singleton(Boolean.TRUE)); | 398 list.removeAll(Collections.singleton(Boolean.TRUE)); |
402 fail(); | 399 fail(); |
403 } catch (UnsupportedOperationException e) { | 400 } catch (UnsupportedOperationException e) { |
404 // expected | 401 // expected |
405 } | 402 } |
406 | 403 |
407 try { | 404 try { |
408 list.removeAll(UNARY_LIST); | 405 list.removeAll(UNARY_LIST); |
409 fail(); | 406 fail(); |
410 } catch (UnsupportedOperationException e) { | 407 } catch (UnsupportedOperationException e) { |
411 // expected | 408 // expected |
412 } | 409 } |
413 | 410 |
414 try { | 411 try { |
415 list.retainAll(Collections.<Boolean>emptyList()); | 412 list.retainAll(Collections.<Boolean>emptyList()); |
416 fail(); | 413 fail(); |
417 } catch (UnsupportedOperationException e) { | 414 } catch (UnsupportedOperationException e) { |
418 // expected | 415 // expected |
419 } | 416 } |
420 | 417 |
421 try { | 418 try { |
422 list.removeAll(Collections.singleton(Boolean.TRUE)); | 419 list.retainAll(Collections.singleton(Boolean.TRUE)); |
423 fail(); | 420 fail(); |
424 } catch (UnsupportedOperationException e) { | 421 } catch (UnsupportedOperationException e) { |
425 // expected | 422 // expected |
426 } | 423 } |
427 | 424 |
428 try { | 425 try { |
429 list.retainAll(UNARY_LIST); | 426 list.retainAll(UNARY_LIST); |
430 fail(); | 427 fail(); |
431 } catch (UnsupportedOperationException e) { | 428 } catch (UnsupportedOperationException e) { |
432 // expected | 429 // expected |
433 } | 430 } |
434 | 431 |
435 try { | 432 try { |
436 list.set(0, false); | 433 list.set(0, true); |
437 fail(); | 434 fail(); |
438 } catch (UnsupportedOperationException e) { | 435 } catch (UnsupportedOperationException e) { |
439 // expected | 436 // expected |
440 } | 437 } |
441 | 438 |
442 try { | 439 try { |
443 list.setBoolean(0, false); | 440 list.setBoolean(0, false); |
444 fail(); | 441 fail(); |
445 } catch (UnsupportedOperationException e) { | 442 } catch (UnsupportedOperationException e) { |
446 // expected | 443 // expected |
447 } | 444 } |
448 } | 445 } |
449 | 446 |
450 private static BooleanArrayList newImmutableBooleanArrayList(boolean... elemen
ts) { | 447 private static BooleanArrayList newImmutableBooleanArrayList(boolean... elemen
ts) { |
451 BooleanArrayList list = new BooleanArrayList(); | 448 BooleanArrayList list = new BooleanArrayList(); |
452 for (boolean element : elements) { | 449 for (boolean element : elements) { |
453 list.addBoolean(element); | 450 list.addBoolean(element); |
454 } | 451 } |
455 list.makeImmutable(); | 452 list.makeImmutable(); |
456 return list; | 453 return list; |
457 } | 454 } |
458 } | 455 } |
OLD | NEW |