use of java.util.AbstractSequentialList 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.AbstractSequentialList 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.AbstractSequentialList 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.AbstractSequentialList 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"));
}
}
use of java.util.AbstractSequentialList in project j2objc by google.
the class AbstractSequentialListTest method test_get.
/**
* @tests java.util.AbstractSequentialList#get(int)
*/
public void test_get() {
AbstractSequentialList list = new MyAbstractSequentialList();
list.add(1);
list.add("value");
assertEquals(1, list.get(0));
assertEquals("value", list.get(1));
// get value by index which is out of bounds
try {
list.get(list.size());
fail("Should throw IndexOutOfBoundsException.");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
list.get(-1);
fail("Should throw IndexOutOfBoundsException.");
} catch (IndexOutOfBoundsException e) {
// expected
}
}
Aggregations