ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArrayListTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CopyOnWriteArrayListTest.java (file contents):
Revision 1.29 by jsr166, Thu May 30 03:28:55 2013 UTC vs.
Revision 1.30 by jsr166, Fri Jan 31 17:58:35 2014 UTC

# Line 500 | Line 500 | public class CopyOnWriteArrayListTest ex
500       * can not store the objects inside the list
501       */
502      public void testToArray_ArrayStoreException() {
503 +        CopyOnWriteArrayList c = new CopyOnWriteArrayList();
504 +        c.add("zfasdfsdf");
505 +        c.add("asdadasd");
506          try {
504            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
505            c.add("zfasdfsdf");
506            c.add("asdadasd");
507              c.toArray(new Long[5]);
508              shouldThrow();
509          } catch (ArrayStoreException success) {}
# Line 513 | Line 513 | public class CopyOnWriteArrayListTest ex
513       * get throws an IndexOutOfBoundsException on a negative index
514       */
515      public void testGet1_IndexOutOfBoundsException() {
516 <        try {
517 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
518 <            c.get(-1);
519 <            shouldThrow();
520 <        } catch (IndexOutOfBoundsException success) {}
516 >        CopyOnWriteArrayList c = populatedArray(5);
517 >        List[] lists = { c, c.subList(1, c.size() - 1) };
518 >        for (List list : lists) {
519 >            try {
520 >                list.get(-1);
521 >                shouldThrow();
522 >            } catch (IndexOutOfBoundsException success) {}
523 >        }
524      }
525  
526      /**
527       * get throws an IndexOutOfBoundsException on a too high index
528       */
529      public void testGet2_IndexOutOfBoundsException() {
530 <        try {
531 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
532 <            c.add("asdasd");
533 <            c.add("asdad");
534 <            c.get(100);
535 <            shouldThrow();
536 <        } catch (IndexOutOfBoundsException success) {}
530 >        CopyOnWriteArrayList c = populatedArray(5);
531 >        List[] lists = { c, c.subList(1, c.size() - 1) };
532 >        for (List list : lists) {
533 >            try {
534 >                list.get(list.size());
535 >                shouldThrow();
536 >            } catch (IndexOutOfBoundsException success) {}
537 >        }
538      }
539  
540      /**
541       * set throws an IndexOutOfBoundsException on a negative index
542       */
543      public void testSet1_IndexOutOfBoundsException() {
544 <        try {
545 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
546 <            c.set(-1,"qwerty");
547 <            shouldThrow();
548 <        } catch (IndexOutOfBoundsException success) {}
544 >        CopyOnWriteArrayList c = populatedArray(5);
545 >        List[] lists = { c, c.subList(1, c.size() - 1) };
546 >        for (List list : lists) {
547 >            try {
548 >                list.set(-1, "qwerty");
549 >                shouldThrow();
550 >            } catch (IndexOutOfBoundsException success) {}
551 >        }
552      }
553  
554      /**
555       * set throws an IndexOutOfBoundsException on a too high index
556       */
557      public void testSet2() {
558 <        try {
559 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
560 <            c.add("asdasd");
561 <            c.add("asdad");
562 <            c.set(100, "qwerty");
563 <            shouldThrow();
564 <        } catch (IndexOutOfBoundsException success) {}
558 >        CopyOnWriteArrayList c = populatedArray(5);
559 >        List[] lists = { c, c.subList(1, c.size() - 1) };
560 >        for (List list : lists) {
561 >            try {
562 >                list.set(list.size(), "qwerty");
563 >                shouldThrow();
564 >            } catch (IndexOutOfBoundsException success) {}
565 >        }
566      }
567  
568      /**
569       * add throws an IndexOutOfBoundsException on a negative index
570       */
571      public void testAdd1_IndexOutOfBoundsException() {
572 <        try {
573 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
574 <            c.add(-1,"qwerty");
575 <            shouldThrow();
576 <        } catch (IndexOutOfBoundsException success) {}
572 >        CopyOnWriteArrayList c = populatedArray(5);
573 >        List[] lists = { c, c.subList(1, c.size() - 1) };
574 >        for (List list : lists) {
575 >            try {
576 >                list.add(-1, "qwerty");
577 >                shouldThrow();
578 >            } catch (IndexOutOfBoundsException success) {}
579 >        }
580      }
581  
582      /**
583       * add throws an IndexOutOfBoundsException on a too high index
584       */
585      public void testAdd2_IndexOutOfBoundsException() {
586 <        try {
587 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
588 <            c.add("asdasd");
589 <            c.add("asdasdasd");
590 <            c.add(100, "qwerty");
591 <            shouldThrow();
592 <        } catch (IndexOutOfBoundsException success) {}
586 >        CopyOnWriteArrayList c = populatedArray(5);
587 >        List[] lists = { c, c.subList(1, c.size() - 1) };
588 >        for (List list : lists) {
589 >            try {
590 >                list.add(list.size() + 1, "qwerty");
591 >                shouldThrow();
592 >            } catch (IndexOutOfBoundsException success) {}
593 >        }
594      }
595  
596      /**
597       * remove throws an IndexOutOfBoundsException on a negative index
598       */
599      public void testRemove1_IndexOutOfBounds() {
600 <        try {
601 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
602 <            c.remove(-1);
603 <            shouldThrow();
604 <        } catch (IndexOutOfBoundsException success) {}
600 >        CopyOnWriteArrayList c = populatedArray(5);
601 >        List[] lists = { c, c.subList(1, c.size() - 1) };
602 >        for (List list : lists) {
603 >            try {
604 >                list.remove(-1);
605 >                shouldThrow();
606 >            } catch (IndexOutOfBoundsException success) {}
607 >        }
608      }
609  
610      /**
611       * remove throws an IndexOutOfBoundsException on a too high index
612       */
613      public void testRemove2_IndexOutOfBounds() {
614 <        try {
615 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
616 <            c.add("asdasd");
617 <            c.add("adasdasd");
618 <            c.remove(100);
619 <            shouldThrow();
620 <        } catch (IndexOutOfBoundsException success) {}
614 >        CopyOnWriteArrayList c = populatedArray(5);
615 >        List[] lists = { c, c.subList(1, c.size() - 1) };
616 >        for (List list : lists) {
617 >            try {
618 >                list.remove(list.size());
619 >                shouldThrow();
620 >            } catch (IndexOutOfBoundsException success) {}
621 >        }
622      }
623  
624      /**
625       * addAll throws an IndexOutOfBoundsException on a negative index
626       */
627      public void testAddAll1_IndexOutOfBoundsException() {
628 <        try {
629 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
630 <            c.addAll(-1,new LinkedList());
631 <            shouldThrow();
632 <        } catch (IndexOutOfBoundsException success) {}
628 >        CopyOnWriteArrayList c = populatedArray(5);
629 >        List[] lists = { c, c.subList(1, c.size() - 1) };
630 >        for (List list : lists) {
631 >            try {
632 >                list.addAll(-1, new LinkedList());
633 >                shouldThrow();
634 >            } catch (IndexOutOfBoundsException success) {}
635 >        }
636      }
637  
638      /**
639       * addAll throws an IndexOutOfBoundsException on a too high index
640       */
641      public void testAddAll2_IndexOutOfBoundsException() {
642 <        try {
643 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
644 <            c.add("asdasd");
645 <            c.add("asdasdasd");
646 <            c.addAll(100, new LinkedList());
647 <            shouldThrow();
648 <        } catch (IndexOutOfBoundsException success) {}
642 >        CopyOnWriteArrayList c = populatedArray(5);
643 >        List[] lists = { c, c.subList(1, c.size() - 1) };
644 >        for (List list : lists) {
645 >            try {
646 >                list.addAll(list.size() + 1, new LinkedList());
647 >                shouldThrow();
648 >            } catch (IndexOutOfBoundsException success) {}
649 >        }
650      }
651  
652      /**
653       * listIterator throws an IndexOutOfBoundsException on a negative index
654       */
655      public void testListIterator1_IndexOutOfBoundsException() {
656 <        try {
657 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
658 <            c.listIterator(-1);
659 <            shouldThrow();
660 <        } catch (IndexOutOfBoundsException success) {}
656 >        CopyOnWriteArrayList c = populatedArray(5);
657 >        List[] lists = { c, c.subList(1, c.size() - 1) };
658 >        for (List list : lists) {
659 >            try {
660 >                list.listIterator(-1);
661 >                shouldThrow();
662 >            } catch (IndexOutOfBoundsException success) {}
663 >        }
664      }
665  
666      /**
667       * listIterator throws an IndexOutOfBoundsException on a too high index
668       */
669      public void testListIterator2_IndexOutOfBoundsException() {
670 <        try {
671 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
672 <            c.add("adasd");
673 <            c.add("asdasdas");
674 <            c.listIterator(100);
675 <            shouldThrow();
676 <        } catch (IndexOutOfBoundsException success) {}
670 >        CopyOnWriteArrayList c = populatedArray(5);
671 >        List[] lists = { c, c.subList(1, c.size() - 1) };
672 >        for (List list : lists) {
673 >            try {
674 >                list.listIterator(list.size() + 1);
675 >                shouldThrow();
676 >            } catch (IndexOutOfBoundsException success) {}
677 >        }
678      }
679  
680      /**
681       * subList throws an IndexOutOfBoundsException on a negative index
682       */
683      public void testSubList1_IndexOutOfBoundsException() {
684 <        try {
685 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
686 <            c.subList(-1,100);
687 <            shouldThrow();
688 <        } catch (IndexOutOfBoundsException success) {}
684 >        CopyOnWriteArrayList c = populatedArray(5);
685 >        List[] lists = { c, c.subList(1, c.size() - 1) };
686 >        for (List list : lists) {
687 >            try {
688 >                list.subList(-1, list.size());
689 >                shouldThrow();
690 >            } catch (IndexOutOfBoundsException success) {}
691 >        }
692      }
693  
694      /**
695       * subList throws an IndexOutOfBoundsException on a too high index
696       */
697      public void testSubList2_IndexOutOfBoundsException() {
698 <        try {
699 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
700 <            c.add("asdasd");
701 <            c.subList(1,100);
702 <            shouldThrow();
703 <        } catch (IndexOutOfBoundsException success) {}
698 >        CopyOnWriteArrayList c = populatedArray(5);
699 >        List[] lists = { c, c.subList(1, c.size() - 1) };
700 >        for (List list : lists) {
701 >            try {
702 >                list.subList(0, list.size() + 1);
703 >                shouldThrow();
704 >            } catch (IndexOutOfBoundsException success) {}
705 >        }
706      }
707  
708      /**
# Line 681 | Line 710 | public class CopyOnWriteArrayListTest ex
710       * is lower then the first
711       */
712      public void testSubList3_IndexOutOfBoundsException() {
713 <        try {
714 <            CopyOnWriteArrayList c = new CopyOnWriteArrayList();
715 <            c.subList(3,1);
716 <            shouldThrow();
717 <        } catch (IndexOutOfBoundsException success) {}
713 >        CopyOnWriteArrayList c = populatedArray(5);
714 >        List[] lists = { c, c.subList(1, c.size() - 1) };
715 >        for (List list : lists) {
716 >            try {
717 >                list.subList(list.size() - 1, 1);
718 >                shouldThrow();
719 >            } catch (IndexOutOfBoundsException success) {}
720 >        }
721      }
722  
723      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines