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;
}
}
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
}
}
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));
}
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
}
}
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
}
}
Aggregations