Code example for Vector

Methods: add, clear

0
            } 
        }; 
         
        try { 
            abstr.add(1, 1);
            fail("ClassCastException expected");
        } catch (ClassCastException ee) {
            //expected 
        } 
         
        abstr = new AbstractList<Integer>() {
            final int forbiddenValue = 33;
            @Override 
            public void add(int index, Integer value) {
                if (value == forbiddenValue) {
                    throw new IllegalArgumentException();
                } 
            } 
     
            @Override 
            public Integer get(int index) {
                return null; 
            } 
     
            @Override 
            public int size() { 
                return 0; 
            } 
        }; 
         
        abstr.add(1, 1);
        try { 
            abstr.add(1, 33);
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException ee) {
            //expected 
        } 
         
        abstr = new ArrayList();
         
        abstr.add(0, "element");
        abstr.add(1, null);
        abstr.add(2, 1);
        abstr.add(3, new Double(33));
 
        try { 
            abstr.add(-3, new Double(33));
            fail("IndexOutOfBoundsException expected");
        } catch (IndexOutOfBoundsException ee) {
            //expected 
        } 
 
        try { 
            abstr.add(abstr.size() + 1, new Double(33));
            fail("IndexOutOfBoundsException expected");
        } catch (IndexOutOfBoundsException ee) {
            //expected 
        } 
    } 
 
    @TestTargetNew( 
        level = TestLevel.COMPLETE, 
        notes = "", 
        method = "addAll", 
        args = {int.class, java.util.Collection.class}
    ) 
    public void test_addAllILjava_util_Collection() { 
        Collection c = new Vector();
        c.add(new Double(33));
        c.add(10);
        c.add("String");
 
        AbstractList abstr = new AbstractList() {
            @Override 
            public Object get(int arg0) {
                return null; 
            } 
 
            @Override 
            public int size() { 
                return 0; 
            } 
        }; 
 
        try { 
            abstr.addAll(0, null);
            fail("NullPointerException expected");
        } catch (NullPointerException ee) {
            //expected 
        } 
 
        try { 
            abstr.addAll(0, c);