1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.collections;
  27 
  28 import org.junit.Before;
  29 import org.junit.Test;
  30 
  31 import java.util.*;
  32 
  33 import static org.junit.Assert.*;
  34 import org.junit.runner.RunWith;
  35 import org.junit.runners.Parameterized;
  36 
  37 
  38 /**
  39  * Tests for iterators of ObservableList.
  40  * 
  41  */
  42 @RunWith(Parameterized.class)
  43 public class ObservableListIteratorTest {
  44 
  45     // ========== Test Fixture ==========
  46     final Callable<? extends List<String>> listFactory;
  47     List<String> list;
  48     ListIterator<String> iter;
  49 
  50     public ObservableListIteratorTest(final Callable<? extends List<String>> listFactory) {
  51         this.listFactory = listFactory;
  52     }
  53 
  54     @Parameterized.Parameters
  55     public static Collection createParameters() {
  56         Object[][] data = new Object[][] {
  57             { TestedObservableLists.ARRAY_LIST },
  58             { TestedObservableLists.LINKED_LIST },
  59             { TestedObservableLists.VETOABLE_LIST },
  60             { TestedObservableLists.CHECKED_OBSERVABLE_ARRAY_LIST },
  61             { TestedObservableLists.SYNCHRONIZED_OBSERVABLE_ARRAY_LIST }
  62          };
  63         return Arrays.asList(data);
  64     }
  65 
  66     @Before
  67     public void setup() throws Exception {
  68         list = listFactory.call();
  69         list.addAll(Arrays.asList("a", "b", "c", "d", "e", "f"));
  70         iter = list.listIterator();
  71     }
  72 
  73     // ========== Utility Functions ==========
  74 
  75     List<String> copyOut(Iterator<String> itr) {
  76         List<String> out = new ArrayList<String>();
  77         while (itr.hasNext()) {
  78             out.add(itr.next());
  79         }
  80         return out;
  81     }
  82 
  83     void advance(Iterator<String> itr, int count) {
  84         for (int i = 0; i < count; i += 1) {
  85             itr.next();
  86         }
  87     }
  88 
  89     void toEnd(Iterator<String> itr) {
  90         while (itr.hasNext()) {
  91             itr.next();
  92         }
  93     }
  94 
  95     void rewind(ListIterator<String> itr) {
  96         while (itr.hasPrevious()) {
  97             itr.previous();
  98         }
  99     }
 100 
 101     List<String> contents(ListIterator<String> itr) {
 102         rewind(itr);
 103         return copyOut(itr);
 104     }
 105 
 106     // ========== Basic Tests ==========
 107 
 108     @Test
 109     public void testCompleteIteration() {
 110         assertEquals("[a, b, c, d, e, f]", copyOut(iter).toString());
 111     }
 112 
 113     @Test
 114     public void testBeginningState() {
 115         assertTrue(iter.hasNext());
 116         assertFalse(iter.hasPrevious());
 117         assertEquals(-1, iter.previousIndex());
 118         assertEquals(0, iter.nextIndex());
 119     }
 120 
 121     @Test
 122     public void testMiddleState() {
 123         advance(iter, 3);
 124         assertTrue(iter.hasNext());
 125         assertTrue(iter.hasPrevious());
 126         assertEquals(2, iter.previousIndex());
 127         assertEquals(3, iter.nextIndex());
 128     }
 129 
 130     @Test
 131     public void testEndState() {
 132         toEnd(iter);
 133         assertFalse(iter.hasNext());
 134         assertTrue(iter.hasPrevious());
 135         assertEquals(5, iter.previousIndex());
 136         assertEquals(6, iter.nextIndex());
 137     }
 138 
 139     @Test
 140     public void testSwitchDirections() {
 141         advance(iter, 2);
 142         assertEquals("c", iter.next());
 143         assertEquals("d", iter.next());
 144         assertEquals("d", iter.previous());
 145         assertEquals("c", iter.previous());
 146         assertEquals("c", iter.next());
 147     }
 148 
 149     @Test(expected = NoSuchElementException.class)
 150     public void testBoundaryStart() {
 151         iter.previous();
 152     }
 153 
 154     @Test(expected = NoSuchElementException.class)
 155     public void testBoundaryEnd() {
 156         advance(iter, 6);
 157         iter.next();
 158     }
 159 
 160     @Test
 161     public void testForEachLoop() {
 162         List<String> output = new ArrayList<String>();
 163         for (String s : list) {
 164             output.add(s);
 165         }
 166         assertEquals(list.toString(), output.toString());
 167     }
 168 
 169     // ========== Add Tests ==========
 170 
 171     @Test
 172     public void testAddBeginning() {
 173         iter.add("X");
 174 
 175         assertEquals(0, iter.previousIndex());
 176         assertEquals(1, iter.nextIndex());
 177         assertEquals("a", iter.next());
 178         assertEquals("[X, a, b, c, d, e, f]", list.toString());
 179     }
 180 
 181     @Test
 182     public void testAddMiddle() {
 183         advance(iter, 3);
 184         iter.add("X");
 185 
 186         assertEquals(3, iter.previousIndex());
 187         assertEquals(4, iter.nextIndex());
 188         assertEquals("d", iter.next());
 189         assertEquals("[a, b, c, X, d, e, f]", list.toString());
 190     }
 191 
 192     @Test
 193     public void testAddEnd() {
 194         advance(iter, 6);
 195         iter.add("X");
 196 
 197         assertEquals(6, iter.previousIndex());
 198         assertEquals(7, iter.nextIndex());
 199         assertFalse(iter.hasNext());
 200         assertEquals("[a, b, c, d, e, f, X]", list.toString());
 201     }
 202 
 203     @Test
 204     public void testPreviousAfterAddBeginning() {
 205         iter.add("X");
 206         assertEquals("X", iter.previous());
 207         assertEquals(-1, iter.previousIndex());
 208         assertEquals(0, iter.nextIndex());
 209         assertEquals("[X, a, b, c, d, e, f]", list.toString());
 210     }
 211 
 212     @Test
 213     public void testPreviousAfterAddMiddle() {
 214         advance(iter, 3);
 215         iter.add("X");
 216         assertEquals("X", iter.previous());
 217         assertEquals(2, iter.previousIndex());
 218         assertEquals(3, iter.nextIndex());
 219         assertEquals("[a, b, c, X, d, e, f]", list.toString());
 220     }
 221 
 222     @Test
 223     public void testPreviousAfterAddEnd() {
 224         advance(iter, 6);
 225         iter.add("X");
 226         assertEquals("X", iter.previous());
 227         assertEquals(5, iter.previousIndex());
 228         assertEquals(6, iter.nextIndex());
 229         assertEquals("[a, b, c, d, e, f, X]", list.toString());
 230     }
 231 
 232     @Test
 233     public void testAddMultiple() {
 234         advance(iter, 3);
 235         iter.add("X");
 236         iter.add("Y");
 237         iter.add("Z");
 238         assertEquals(5, iter.previousIndex());
 239         assertEquals(6, iter.nextIndex());
 240         assertEquals("d", iter.next());
 241         assertEquals("d", iter.previous());
 242         assertEquals("Z", iter.previous());
 243         assertEquals("[a, b, c, X, Y, Z, d, e, f]", list.toString());
 244     }
 245 
 246     @Test
 247     public void testAddAfterPrevious() {
 248         advance(iter, 3);
 249         iter.previous(); // c
 250         iter.add("X");
 251         assertEquals(2, iter.previousIndex());
 252         assertEquals(3, iter.nextIndex());
 253         assertEquals("[a, b, X, c, d, e, f]", list.toString());
 254     }
 255 
 256     @Test
 257     public void testAddAfterRemove() {
 258         advance(iter, 3);
 259         iter.remove();
 260         iter.add("X");
 261         assertEquals(2, iter.previousIndex());
 262         assertEquals(3, iter.nextIndex());
 263         assertEquals("[a, b, X, d, e, f]", list.toString());
 264     }
 265 
 266     @Test
 267     public void testAddAfterSet() {
 268         advance(iter, 3);
 269         iter.set("X");
 270         iter.add("Y");
 271         assertEquals(3, iter.previousIndex());
 272         assertEquals(4, iter.nextIndex());
 273         assertEquals("[a, b, X, Y, d, e, f]", list.toString());
 274     }
 275 
 276     // ========== Remove Tests ==========
 277 
 278     @Test
 279     public void testRemoveBeginning() {
 280         iter.next();
 281         iter.remove();
 282         assertEquals(-1, iter.previousIndex());
 283         assertEquals(0, iter.nextIndex());
 284         assertEquals("[b, c, d, e, f]", list.toString());
 285     }
 286 
 287     @Test
 288     public void testRemoveMiddle() {
 289         advance(iter, 3);
 290         iter.remove();
 291         assertEquals(1, iter.previousIndex());
 292         assertEquals(2, iter.nextIndex());
 293         assertEquals("[a, b, d, e, f]", list.toString());
 294     }
 295 
 296     @Test
 297     public void testRemoveEnd() {
 298         toEnd(iter);
 299         iter.remove();
 300         assertEquals(4, iter.previousIndex());
 301         assertEquals(5, iter.nextIndex());
 302         assertEquals("[a, b, c, d, e]", list.toString());
 303     }
 304 
 305     @Test
 306     public void testRemoveAfterPrevious() {
 307         advance(iter, 4);
 308         iter.previous(); // d
 309         iter.previous(); // c
 310         iter.remove();
 311         assertEquals(1, iter.previousIndex());
 312         assertEquals(2, iter.nextIndex());
 313         assertEquals("[a, b, d, e, f]", list.toString());
 314     }
 315 
 316     @Test
 317     public void testRemoveAfterSet() {
 318         advance(iter, 3);
 319         iter.set("X");
 320         iter.remove();
 321         assertEquals(1, iter.previousIndex());
 322         assertEquals(2, iter.nextIndex());
 323         assertEquals("[a, b, d, e, f]", list.toString());
 324     }
 325 
 326     @Test(expected = IllegalStateException.class)
 327     public void testRemoveInitialThrowsException() {
 328         iter.remove();
 329     }
 330 
 331     @Test
 332     public void testRemoveTwiceThrowsException() {
 333         iter.next();
 334         iter.remove();
 335         try { iter.remove(); } catch (IllegalStateException e) {return;}
 336         fail("Expected IllegalStateException");
 337     }
 338 
 339     @Test
 340     public void testRemoveAfterAddThrowsException() {
 341         iter.next();
 342         iter.add("X");
 343         try { iter.remove(); } catch (IllegalStateException e) {return;}
 344         fail("Expected IllegalStateException");
 345     }
 346 
 347     // ========== Set Tests ==========
 348 
 349     @Test
 350     public void testSetBeginning() {
 351         iter.next();
 352         iter.set("X");
 353         assertEquals(0, iter.previousIndex());
 354         assertEquals(1, iter.nextIndex());
 355         assertEquals("[X, b, c, d, e, f]", list.toString());
 356     }
 357 
 358     @Test
 359     public void testSetMiddle() {
 360         advance(iter, 3);
 361         iter.set("X");
 362         assertEquals(2, iter.previousIndex());
 363         assertEquals(3, iter.nextIndex());
 364         assertEquals("[a, b, X, d, e, f]", list.toString());
 365     }
 366 
 367     @Test
 368     public void testSetEnd() {
 369         toEnd(iter);
 370         iter.set("X");
 371         assertEquals(5, iter.previousIndex());
 372         assertEquals(6, iter.nextIndex());
 373         assertEquals("[a, b, c, d, e, X]", list.toString());
 374     }
 375 
 376     @Test
 377     public void testSetTwice() {
 378         advance(iter, 3);
 379         iter.set("X");
 380         assertEquals(2, iter.previousIndex());
 381         assertEquals(3, iter.nextIndex());
 382         assertEquals("[a, b, X, d, e, f]", list.toString());
 383         iter.set("Y");
 384         assertEquals(2, iter.previousIndex());
 385         assertEquals(3, iter.nextIndex());
 386         assertEquals("[a, b, Y, d, e, f]", list.toString());
 387     }
 388 
 389     @Test
 390     public void testSetAfterPrevious() {
 391         advance(iter, 4);
 392         iter.previous(); // d
 393         iter.previous(); // c
 394         iter.set("X");
 395         assertEquals(1, iter.previousIndex());
 396         assertEquals(2, iter.nextIndex());
 397         assertEquals("[a, b, X, d, e, f]", list.toString());
 398     }
 399 
 400     @Test
 401     public void testSetInitialThrowsException() {
 402         try { iter.set("X"); } catch (IllegalStateException e) {return;}
 403         fail("Expected IllegalStateException");
 404     }
 405 
 406     @Test
 407     public void testSetAfterAddThrowsException() {
 408         iter.next();
 409         iter.add("X");
 410         try { iter.set("Y"); } catch (IllegalStateException e) {return;}
 411         fail("Expected IllegalStateException");
 412     }
 413 
 414     @Test
 415     public void testSetAfterRemoveThrowsException() {
 416         iter.next();
 417         iter.remove();
 418         try { iter.set("X"); } catch (IllegalStateException e) {return;}
 419         fail("Expected IllegalStateException");
 420     }
 421 
 422     // ========== Positioned Iterator Tests ==========
 423 
 424     @Test
 425     public void testPosBeginning() {
 426         iter = list.listIterator(0);
 427         assertFalse(iter.hasPrevious());
 428         assertTrue(iter.hasNext());
 429         assertEquals(-1, iter.previousIndex());
 430         assertEquals(0, iter.nextIndex());
 431         assertEquals("a", iter.next());
 432     }
 433 
 434     @Test
 435     public void testPosMiddle() {
 436         iter = list.listIterator(3);
 437         assertTrue(iter.hasPrevious());
 438         assertTrue(iter.hasNext());
 439         assertEquals(2, iter.previousIndex());
 440         assertEquals(3, iter.nextIndex());
 441         assertEquals("d", iter.next());
 442     }
 443 
 444     @Test
 445     public void testPosEnd() {
 446         iter = list.listIterator(6);
 447         assertTrue(iter.hasPrevious());
 448         assertFalse(iter.hasNext());
 449         assertEquals(5, iter.previousIndex());
 450         assertEquals(6, iter.nextIndex());
 451         assertEquals("f", iter.previous());
 452     }
 453 
 454     @Test
 455     public void testPosAdd() {
 456         iter = list.listIterator(3);
 457         iter.add("X");
 458         assertEquals(3, iter.previousIndex());
 459         assertEquals(4, iter.nextIndex());
 460         assertEquals("[a, b, c, X, d, e, f]", list.toString());
 461     }
 462 
 463     @Test
 464     public void testPosInitialRemoveThrowsException() {
 465         iter = list.listIterator(3);
 466         try { iter.remove(); } catch (IllegalStateException e) {return;}
 467         fail("Expected IllegalStateException");
 468     }
 469 
 470     @Test
 471     public void testPosInitialSetThrowsException() {
 472         iter = list.listIterator(3);
 473         try { iter.set("X"); } catch (IllegalStateException e) {return;}
 474         fail("Expected IllegalStateException");
 475     }
 476 
 477     // ========== Concurrency Tests ==========
 478 
 479     @Test
 480     public void testConcurrencyAddIteratorNext() {
 481         iter = list.listIterator();
 482         list.add("aa");
 483         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 484         fail("Expected ConcurrentModificationException");
 485     }
 486     @Test
 487     public void testConcurrencyAddIndexedIteratorNext() {
 488         iter = list.listIterator();
 489         list.add(1, "aa");
 490         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 491         fail("Expected ConcurrentModificationException");
 492     }
 493     @Test
 494     public void testConcurrencyRemoveIteratorNext() {
 495         iter = list.listIterator();
 496         list.remove("b");
 497         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 498         fail("Expected ConcurrentModificationException");
 499     }
 500 
 501     @Test
 502     public void testConcurrencyRemoveIndexedIteratorNext() {
 503         iter = list.listIterator();
 504         list.remove(2);
 505         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 506         fail("Expected ConcurrentModificationException");
 507     }
 508     @Test
 509     public void testConcurrencyAddAllIteratorNext() {
 510         iter = list.listIterator();
 511         list.addAll(Collections.singleton("f"));
 512         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 513         fail("Expected ConcurrentModificationException");
 514     }
 515     @Test
 516     public void testConcurrencyAddAllIndexedIteratorNext() {
 517         iter = list.listIterator();
 518         list.addAll(1, Collections.singleton("f"));
 519         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 520         fail("Expected ConcurrentModificationException");
 521     }
 522     
 523     @Test
 524     public void testConcurrencyGetIteratorNext() {
 525         iter = list.listIterator();
 526         list.get(2);
 527         iter.next();
 528     }
 529 
 530     @Test
 531     public void testConcurrencyRemoveAllIteratorNext() {
 532         iter = list.listIterator();
 533         list.removeAll(Arrays.asList("a", "c"));
 534         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 535         fail("Expected ConcurrentModificationException");
 536     }
 537 
 538     @Test
 539     public void testConcurrencyRetainAllIteratorNext() {
 540         iter = list.listIterator();
 541         list.retainAll(Arrays.asList("a", "c"));
 542         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 543         fail("Expected ConcurrentModificationException");
 544     }
 545 
 546     @Test
 547     public void testConcurrencyIteratorIteratorNext() {
 548         iter = list.listIterator();
 549         final Iterator<String> iterator = list.iterator();
 550         iterator.next();
 551         iterator.remove();
 552         try { iter.next(); } catch (ConcurrentModificationException e) {return;}
 553         fail("Expected ConcurrentModificationException");
 554     }
 555     @Test
 556     public void testConcurrencyAddIteratorPrevious() {
 557         iter = list.listIterator(2);
 558         list.add("aa");
 559         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 560         fail("Expected ConcurrentModificationException");
 561     }
 562     @Test
 563     public void testConcurrencyAddIndexedIteratorPrevious() {
 564         iter = list.listIterator(2);
 565         list.add(1, "aa");
 566         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 567         fail("Expected ConcurrentModificationException");
 568     }
 569     @Test
 570     public void testConcurrencyRemoveIteratorPrevious() {
 571         iter = list.listIterator(2);
 572         list.remove("b");
 573         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 574         fail("Expected ConcurrentModificationException");
 575     }
 576 
 577     @Test
 578     public void testConcurrencyRemoveIndexedIteratorPrevious() {
 579         iter = list.listIterator(2);
 580         list.remove(2);
 581         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 582         fail("Expected ConcurrentModificationException");
 583     }
 584     @Test
 585     public void testConcurrencyAddAllIteratorPrevious() {
 586         iter = list.listIterator(2);
 587         list.addAll(Collections.singleton("f"));
 588         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 589         fail("Expected ConcurrentModificationException");
 590     }
 591     @Test
 592     public void testConcurrencyAddAllIndexedIteratorPrevious() {
 593         iter = list.listIterator(2);
 594         list.addAll(1, Collections.singleton("f"));
 595         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 596         fail("Expected ConcurrentModificationException");
 597     }
 598 
 599     @Test
 600     public void testConcurrencyGetIteratorPrevious() {
 601         iter = list.listIterator(2);
 602         list.get(2);
 603         iter.previous();
 604     }
 605 
 606     @Test
 607     public void testConcurrencyRemoveAllIteratorPrevious() {
 608         iter = list.listIterator(2);
 609         list.removeAll(Arrays.asList("a", "c"));
 610         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 611         fail("Expected ConcurrentModificationException");
 612     }
 613 
 614     @Test
 615     public void testConcurrencyRetainAllIteratorPrevious() {
 616         iter = list.listIterator(2);
 617         list.retainAll(Arrays.asList("a", "c"));
 618         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 619         fail("Expected ConcurrentModificationException");
 620     }
 621 
 622     @Test
 623     public void testConcurrencyIteratorIteratorPrevious() {
 624         iter = list.listIterator(2);
 625         final Iterator<String> iterator = list.iterator();
 626         iterator.next();
 627         iterator.remove();
 628         try { iter.previous(); } catch (ConcurrentModificationException e) {return;}
 629         fail("Expected ConcurrentModificationException");
 630     }
 631 
 632     @Test
 633     public void testConcurrencyAddIteratorRemove() {
 634         iter = list.listIterator();
 635         iter.next();
 636         list.add("aa");
 637         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 638         fail("Expected ConcurrentModificationException");
 639     }
 640     
 641     @Test
 642     public void testConcurrencyAddIndexedIteratorRemove() {
 643         iter = list.listIterator();
 644         iter.next();
 645         list.add(1, "aa");
 646         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 647         fail("Expected ConcurrentModificationException");
 648     }
 649 
 650     @Test
 651     public void testConcurrencyRemoveIteratorRemove() {
 652         iter = list.listIterator();
 653         iter.next();
 654         list.remove("b");
 655         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 656         fail("Expected ConcurrentModificationException");
 657     }
 658 
 659     @Test
 660     public void testConcurrencyRemoveIndexedIteratorRemove() {
 661         iter = list.listIterator();
 662         iter.next();
 663         list.remove(2);
 664         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 665         fail("Expected ConcurrentModificationException");
 666     }
 667     @Test
 668     public void testConcurrencyAddAllIteratorRemove() {
 669         iter = list.listIterator();
 670         iter.next();
 671         list.addAll(Collections.singleton("f"));
 672         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 673         fail("Expected ConcurrentModificationException");
 674     }
 675     @Test
 676     public void testConcurrencyAddAllIndexedIteratorRemove() {
 677         iter = list.listIterator();
 678         iter.next();
 679         list.addAll(1, Collections.singleton("f"));
 680         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 681         fail("Expected ConcurrentModificationException");
 682     }
 683 
 684     @Test
 685     public void testConcurrencyGetIteratorRemove() {
 686         iter = list.listIterator();
 687         iter.next();
 688         list.get(2);
 689         iter.remove();
 690     }
 691 
 692     @Test
 693     public void testConcurrencyRemoveAllIteratorRemove() {
 694         iter = list.listIterator();
 695         iter.next();
 696         list.removeAll(Arrays.asList("a", "c"));
 697         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 698         fail("Expected ConcurrentModificationException");
 699     }
 700 
 701     @Test
 702     public void testConcurrencyRetainAllIteratorRemove() {
 703         iter = list.listIterator();
 704         iter.next();
 705         list.retainAll(Arrays.asList("a", "c"));
 706         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 707         fail("Expected ConcurrentModificationException");
 708     }
 709 
 710     @Test
 711     public void testConcurrencyIteratorIteratorRemove() {
 712         iter = list.listIterator();
 713         iter.next();
 714         final Iterator<String> iterator = list.iterator();
 715         iterator.next();
 716         iterator.remove();
 717         try { iter.remove(); } catch (ConcurrentModificationException e) {return;}
 718         fail("Expected ConcurrentModificationException");
 719     }
 720 
 721     @Test
 722     public void testConcurrencyAddIteratorSet() {
 723         iter = list.listIterator();
 724         iter.next();
 725         list.add("aa");
 726         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 727         fail("Expected ConcurrentModificationException");
 728     }
 729 
 730     @Test
 731     public void testConcurrencyAddIndexedIteratorSet() {
 732         iter = list.listIterator();
 733         iter.next();
 734         list.add(1, "aa");
 735         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 736         fail("Expected ConcurrentModificationException");
 737     }
 738 
 739     @Test
 740     public void testConcurrencyRemoveIteratorSet() {
 741         iter = list.listIterator();
 742         iter.next();
 743         list.remove("b");
 744         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 745         fail("Expected ConcurrentModificationException");
 746     }
 747 
 748     @Test
 749     public void testConcurrencyRemoveIndexedIteratorSet() {
 750         iter = list.listIterator();
 751         iter.next();
 752         list.remove(2);
 753         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 754         fail("Expected ConcurrentModificationException");
 755     }
 756     @Test
 757     public void testConcurrencyAddAllIteratorSet() {
 758         iter = list.listIterator();
 759         iter.next();
 760         list.addAll(Collections.singleton("f"));
 761         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 762         fail("Expected ConcurrentModificationException");
 763     }
 764     @Test
 765     public void testConcurrencyAddAllIndexedIteratorSet() {
 766         iter = list.listIterator();
 767         iter.next();
 768         list.addAll(1, Collections.singleton("f"));
 769         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 770         fail("Expected ConcurrentModificationException");
 771     }
 772 
 773     @Test
 774     public void testConcurrencyGetIteratorSet() {
 775         iter = list.listIterator();
 776         iter.next();
 777         list.get(2);
 778         iter.set("x");
 779     }
 780 
 781     @Test
 782     public void testConcurrencyRemoveAllIteratorSet() {
 783         iter = list.listIterator();
 784         iter.next();
 785         list.removeAll(Arrays.asList("a", "c"));
 786         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 787         fail("Expected ConcurrentModificationException");
 788     }
 789 
 790     @Test
 791     public void testConcurrencyRetainAllIteratorSet() {
 792         iter = list.listIterator();
 793         iter.next();
 794         list.retainAll(Arrays.asList("a", "c"));
 795         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 796         fail("Expected ConcurrentModificationException");
 797     }
 798 
 799     @Test
 800     public void testConcurrencyIteratorIteratorSet() {
 801         iter = list.listIterator();
 802         iter.next();
 803         final Iterator<String> iterator = list.iterator();
 804         iterator.next();
 805         iterator.remove();
 806         try { iter.set("x"); } catch (ConcurrentModificationException e) {return;}
 807         fail("Expected ConcurrentModificationException");
 808     }
 809 }