public void testRemoveLast() { iter = list.listIterator(numElements); Object last = iter.previous(); iter.remove(); assertEquals(list.size(), numElements - 1); assertTrue(last.equals(numElements - 1)); }
public void testRemoveFirst() { iter = list.listIterator(); Object first = iter.next(); iter.remove(); assertEquals(list.size(), numElements - 1); assertTrue(first.equals(0)); }
/** * You need to have called next (or previous) to call remove Try to do remove without calling next * and see that an exception is thrown */ public void testTryRemoveWithoutNext() { boolean threwException = false; iter = list.listIterator(); try { iter.remove(); // Try removing without having called next } catch (IllegalStateException e) { threwException = true; // Control should get to this point } assertTrue(threwException); }