use of org.datanucleus.store.types.SCOListIterator in project datanucleus-core by datanucleus.
the class SCOListIteratorTest method testIteratorNextPrevious.
/**
* Test of next/previous behaviour.
*/
public void testIteratorNextPrevious() {
LinkedList<String> list = new LinkedList<String>();
list.add("First");
list.add("Second");
list.add("Third");
List<String> sco = new ArrayList<String>();
sco.addAll(list);
SCOListIterator iter = new SCOListIterator(sco, null, list, null, true, 0);
assertTrue("hasNext returns false!", iter.hasNext());
try {
iter.set("Fifth");
fail("set() before next()/previous() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
}
assertTrue("hasNext returns false!", iter.hasNext());
Object obj = iter.next();
assertEquals("First", obj);
// Test use of set() now that next() has been called.
// Set the first element
iter.set("Fifth");
assertTrue("hasNext returns false!", iter.hasNext());
obj = iter.next();
assertEquals("Second", obj);
assertTrue("hasNext returns false!", iter.hasNext());
obj = iter.next();
assertEquals("Third", obj);
assertFalse("hasNext returns true!", iter.hasNext());
try {
iter.next();
fail("call to next() succeeded but is already at end of list");
} catch (NoSuchElementException nsee) {
// Expected
}
}
use of org.datanucleus.store.types.SCOListIterator in project datanucleus-core by datanucleus.
the class SCOListIteratorTest method testIteratorAddRemoveSet.
/**
* Test of add/remove/set behaviour.
*/
public void testIteratorAddRemoveSet() {
LinkedList<String> list = new LinkedList<String>();
list.add("First");
List<String> sco = new ArrayList<String>();
sco.addAll(list);
SCOListIterator iter = new SCOListIterator(sco, null, list, null, true, 0);
try {
iter.remove();
fail("remove() before next()/previous() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
}
try {
iter.set("BAD");
fail("set() before next()/previous() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
}
iter.next();
iter.set("Second");
assertEquals("Second", iter.previous());
assertEquals("Second", iter.next());
iter.remove();
iter.add("Third");
iter.add("Fourth");
assertEquals("Fourth", iter.previous());
assertEquals("Fourth", iter.next());
iter.remove();
try {
iter.remove();
fail("remove() after remove() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
assertEquals(1, sco.size());
}
try {
iter.set("BAD");
fail("set() after remove() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
}
iter.add("Fifth");
try {
iter.remove();
fail("remove() after add() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
}
try {
iter.set("BAD");
fail("set() after add() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
}
iter.previous();
iter.remove();
iter.add("Sixth");
iter.previous();
iter.set("Seventh");
assertEquals("Seventh", iter.next());
assertEquals("Seventh", iter.previous());
iter.remove();
iter.previous();
iter.remove();
assertTrue(sco.isEmpty());
}
use of org.datanucleus.store.types.SCOListIterator in project datanucleus-core by datanucleus.
the class SCOListIteratorTest method testIteratorNextPreviousStartNegative.
/**
* Test of next/previous behaviour with an iterator starting at -1.
*/
public void testIteratorNextPreviousStartNegative() {
LinkedList<String> list = new LinkedList<String>();
list.add("First");
list.add("Second");
list.add("Third");
List<String> sco = new ArrayList<String>();
sco.addAll(list);
SCOListIterator iter = new SCOListIterator(sco, null, list, null, true, -1);
assertTrue("hasNext returns false!", iter.hasNext());
try {
iter.set("Fifth");
fail("set() before next()/previous() succeeded but should fail");
} catch (IllegalStateException ise) {
// Expected
}
assertTrue("hasNext returns false!", iter.hasNext());
Object obj = iter.next();
assertEquals("First", obj);
// Test use of set() now that next() has been called.
// Set the first element
iter.set("Fifth");
assertTrue("hasNext returns false!", iter.hasNext());
obj = iter.next();
assertEquals("Second", obj);
assertTrue("hasNext returns false!", iter.hasNext());
obj = iter.next();
assertEquals("Third", obj);
assertFalse("hasNext returns true!", iter.hasNext());
try {
iter.next();
fail("call to next() succeeded but is already at end of list");
} catch (NoSuchElementException nsee) {
// Expected
}
}
Aggregations