use of java.util.ListIterator in project robovm by robovm.
the class AbstractListTest method test_subListII.
/**
* java.util.AbstractList#subList(int, int)
*/
public void test_subListII() {
// Test each of the SubList operations to ensure a
// ConcurrentModificationException does not occur on an AbstractList
// which does not update modCount
SimpleList mList = new SimpleList();
mList.add(new Object());
mList.add(new Object());
List sList = mList.subList(0, 2);
// calls add(int, Object)
sList.add(new Object());
sList.get(0);
sList.add(0, new Object());
sList.get(0);
sList.addAll(Arrays.asList(new String[] { "1", "2" }));
sList.get(0);
sList.addAll(0, Arrays.asList(new String[] { "3", "4" }));
sList.get(0);
sList.remove(0);
sList.get(0);
ListIterator lit = sList.listIterator();
lit.add(new Object());
lit.next();
lit.remove();
lit.next();
// calls removeRange()
sList.clear();
sList.add(new Object());
// test the type of sublist that is returned
List al = new ArrayList();
for (int i = 0; i < 10; i++) {
al.add(new Integer(i));
}
assertTrue("Sublist returned should have implemented Random Access interface", al.subList(3, 7) instanceof RandomAccess);
List ll = new LinkedList();
for (int i = 0; i < 10; i++) {
ll.add(new Integer(i));
}
assertTrue("Sublist returned should not have implemented Random Access interface", !(ll.subList(3, 7) instanceof RandomAccess));
}
use of java.util.ListIterator in project robovm by robovm.
the class AbstractSequentialListTest method test_addILjava_lang_Object.
public void test_addILjava_lang_Object() {
AbstractSequentialList asl = new AbstractSequentialList() {
@Override
public int size() {
return 0;
}
@Override
public ListIterator listIterator(int index) {
return new Mock_unsupportedListIterator();
}
};
try {
asl.add(0, 1);
fail("UnsupportedOperationException expected");
} catch (UnsupportedOperationException e) {
//expected
}
asl = new AbstractSequentialList() {
@Override
public int size() {
return 0;
}
@Override
public ListIterator listIterator(int index) {
return new Mock_ListIterator();
}
};
try {
asl.add(0, "String");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException ee) {
//expected
}
try {
asl.add(0, null);
fail("NullPointerException expected");
} catch (NullPointerException ee) {
//expected
}
//ClassCastException can not be checked for this method.
asl.add(0, 1);
asl = new LinkedList();
try {
asl.add(-1, 1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException ee) {
//expected
}
asl.add(0, 1);
try {
asl.add(2, 1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException ee) {
//expected
}
}
use of java.util.ListIterator in project robovm by robovm.
the class AbstractSequentialListTest method test_iterrator.
public void test_iterrator() {
AbstractSequentialList asl = new AbstractSequentialList() {
@Override
public int size() {
return 0;
}
@Override
public ListIterator listIterator(int index) {
return new Mock_unsupportedListIterator();
}
};
assertTrue(asl.iterator().getClass().toString().contains("Mock_unsupportedListIterator"));
asl = new AbstractSequentialList() {
@Override
public int size() {
return 0;
}
@Override
public ListIterator listIterator(int index) {
return new Mock_ListIterator();
}
};
assertTrue(asl.iterator().getClass().toString().contains("Mock_ListIterator"));
asl = new AbstractSequentialList() {
@Override
public int size() {
return 0;
}
@Override
public ListIterator listIterator(int index) {
return null;
}
};
assertNull(asl.iterator());
}
use of java.util.ListIterator in project robovm by robovm.
the class AbstractSequentialListTest method test_addAllILjava_util_Collection.
public void test_addAllILjava_util_Collection() {
AbstractSequentialList asl = new AbstractSequentialList() {
@Override
public int size() {
return 0;
}
@Override
public ListIterator listIterator(int index) {
return new Mock_unsupportedListIterator();
}
};
Collection strV = new Vector<String>();
strV.add("String");
strV.add("1");
strV.add("3.14");
try {
asl.addAll(0, strV);
fail("UnsupportedOperationException expected.");
} catch (UnsupportedOperationException ee) {
//expected
}
try {
asl.addAll(0, null);
fail("NullPointerException expected");
} catch (NullPointerException ee) {
//expected
}
//ClassCastException can not be checked for this method.
asl = new AbstractSequentialList() {
@Override
public int size() {
return 0;
}
@Override
public ListIterator listIterator(int index) {
return new Mock_ListIterator();
}
};
try {
asl.addAll(0, strV);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
//expected
}
strV.remove("String");
strV.add(null);
try {
asl.addAll(0, strV);
fail("NullPointerException expected");
} catch (NullPointerException e) {
//expected
}
strV.remove(null);
asl.addAll(0, strV);
asl = new LinkedList();
try {
asl.addAll(-10, strV);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {
//expected
}
try {
asl.addAll(1, strV);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {
//expected
}
}
use of java.util.ListIterator in project robovm by robovm.
the class AbstractSequentialListTest method test_removeI.
public void test_removeI() {
AbstractSequentialList asl = new AbstractSequentialList() {
String[] buff = { "0", "1", "2", "3", "4", "5" };
int currPos = 0;
@Override
public int size() {
return buff.length;
}
@Override
public ListIterator listIterator(int index) {
currPos = index;
return new ListIterator() {
public void add(Object o) {
}
public boolean hasNext() {
return true;
}
public boolean hasPrevious() {
return false;
}
public Object next() {
return buff[currPos];
}
public int nextIndex() {
return 0;
}
public Object previous() {
return null;
}
public int previousIndex() {
return 0;
}
public void remove() {
buff[currPos] = "removed element";
}
public void set(Object o) {
}
};
}
};
try {
asl.remove(asl.size() + 1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {
//expected
}
try {
asl.remove(-1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {
//expected
}
for (int i = 0; i < asl.size(); i++) {
assertFalse(asl.get(i).toString().contains("removed element"));
asl.remove(i);
assertTrue(asl.get(i).toString().contains("removed element"));
}
}
Aggregations