Search in sources :

Example 16 with AbstractList

use of java.util.AbstractList in project robovm by robovm.

the class ConcurrentModTest method testAddAll.

/*
     * Test method for 'java.util.AbstractList.subList(int, int)'
     */
public void testAddAll() {
    AbstractList al = new ArrayList();
    Double one = new Double(1.0);
    Double two = new Double(2.0);
    Double three = new Double(3.0);
    Double four = new Double(4.0);
    al.add(one);
    al.add(two);
    al.add(three);
    al.add(four);
    List sub = al.subList(1, 3);
    assertEquals(2, sub.size());
    // the sub.get(1) is 3.0
    assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
    assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
    // remove the 2.0
    al.remove(1);
    try {
        // illegal call the subList's method addAll(int,Collection).
        Collection c = new Vector();
        Double five = new Double(5.0);
        c.add(five);
        sub.addAll(1, c);
        fail("It should throws ConcurrentModificationException.");
    } catch (ConcurrentModificationException e) {
        return;
    }
}
Also used : AbstractList(java.util.AbstractList) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) List(java.util.List) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Vector(java.util.Vector)

Example 17 with AbstractList

use of java.util.AbstractList in project robovm by robovm.

the class ConcurrentModTest method test_addILjava_lang_Object.

public void test_addILjava_lang_Object() {
    AbstractList abstr = new AbstractList() {

        @Override
        public Object get(int arg0) {
            return null;
        }

        @Override
        public int size() {
            return 0;
        }
    };
    try {
        abstr.add(1, null);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
    //ecpected
    }
    abstr = new AbstractList<Double>() {

        @Override
        public void add(int index, Double value) {
        }

        @Override
        public Double get(int index) {
            return null;
        }

        @Override
        public int size() {
            return 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
    }
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList)

Example 18 with AbstractList

use of java.util.AbstractList in project robovm by robovm.

the class ConcurrentModTest method test_equalsLjava_lang_Object.

public void test_equalsLjava_lang_Object() {
    Collection c = new Vector();
    c.add(new Double(33));
    c.add(10);
    c.add("String");
    AbstractList abstr = new ArrayList();
    AbstractList abstr1 = new ArrayList();
    assertFalse(abstr.equals(this));
    abstr.add(new Double(33));
    abstr.add(10);
    abstr.add("String");
    assertTrue(abstr.equals(c));
    abstr1.addAll(c);
    assertTrue(abstr.equals(abstr1));
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Vector(java.util.Vector)

Example 19 with AbstractList

use of java.util.AbstractList in project robovm by robovm.

the class ConcurrentModTest method testRemove.

/*
     * Test method for 'java.util.AbstractList.subList(int, int)'
     */
public void testRemove() {
    AbstractList al = new ArrayList();
    Double one = new Double(1.0);
    Double two = new Double(2.0);
    Double three = new Double(3.0);
    Double four = new Double(4.0);
    al.add(one);
    al.add(two);
    al.add(three);
    al.add(four);
    List sub = al.subList(1, 3);
    assertEquals(2, sub.size());
    // the sub.get(1) is 3.0
    assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
    assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
    // remove the 2.0
    al.remove(1);
    try {
        // illegal call the subList's method remove(int).
        sub.remove(1);
        fail("It should throws ConcurrentModificationException.");
    } catch (ConcurrentModificationException e) {
        return;
    }
    try {
        sub.remove(-1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
    try {
        sub.remove(sub.size() + 1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
    al = new AbstractList() {

        @Override
        public Object get(int index) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public int size() {
            // TODO Auto-generated method stub
            return 0;
        }
    };
    try {
        al.remove(1);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException ee) {
    //expected
    }
}
Also used : AbstractList(java.util.AbstractList) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) List(java.util.List) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList)

Example 20 with AbstractList

use of java.util.AbstractList in project robovm by robovm.

the class ConcurrentModTest method test_setILjava_lang_Object.

public void test_setILjava_lang_Object() {
    Collection c = new Vector();
    c.add(new Double(33));
    c.add(10);
    c.add("String");
    AbstractList abstr1 = new ArrayList();
    AbstractList abstr2 = new ArrayList();
    abstr1.addAll(c);
    abstr2.addAll(c);
    assertTrue(abstr1.equals(abstr2));
    abstr1.set(1, 1);
    assertFalse(abstr1.equals(abstr2));
    try {
        abstr1.set(abstr1.size() + 1, 1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
    try {
        abstr1.set(-1, 1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
    AbstractList abstr = new AbstractList() {

        @Override
        public Object get(int index) {
            return null;
        }

        @Override
        public int size() {
            return 0;
        }
    };
    try {
        abstr.set(0, null);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException ee) {
    //expected
    }
    abstr = new AbstractList<Double>() {

        @Override
        public Double set(int index, Double value) {
            return value;
        }

        @Override
        public Double get(int index) {
            return null;
        }

        @Override
        public int size() {
            return 0;
        }
    };
    try {
        abstr.set(0, 1);
        fail("ClassCastException expected");
    } catch (ClassCastException ee) {
    //expected
    }
    abstr = new AbstractList<Integer>() {

        final int forbiddenValue = 33;

        @Override
        public Integer set(int index, Integer value) {
            if (value == forbiddenValue) {
                throw new IllegalArgumentException();
            }
            return value;
        }

        @Override
        public Integer get(int index) {
            return null;
        }

        @Override
        public int size() {
            return 0;
        }
    };
    try {
        abstr.set(0, 33);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException ee) {
    //expected
    }
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Vector(java.util.Vector)

Aggregations

AbstractList (java.util.AbstractList)25 ArrayList (java.util.ArrayList)19 List (java.util.List)9 Collection (java.util.Collection)5 ConcurrentModificationException (java.util.ConcurrentModificationException)5 Vector (java.util.Vector)4 ListIterator (java.util.ListIterator)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 RandomAccess (java.util.RandomAccess)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Query (org.apache.lucene.search.Query)2 Test (org.junit.Test)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 TestingLoader (dagger.internal.TestingLoader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 Array (java.lang.reflect.Array)1