net.sf.molae.pipe.test
Class ListIteratorTest<B extends ListIterator<E>,E>

java.lang.Object
  extended by org.junit.Assert
      extended by net.sf.molae.pipe.test.ObjectTest<B>
          extended by net.sf.molae.pipe.test.IteratorTest<B>
              extended by net.sf.molae.pipe.test.ListIteratorTest<B,E>

public class ListIteratorTest<B extends ListIterator<E>,E>
extends IteratorTest<B>

Test methods to check the contract of list iterator implementing classes.


Constructor Summary
protected ListIteratorTest(B testObject, List<E> list, int index)
          Creates a new test with the specified candidate.
 
Method Summary
 void assertConsistency()
          Checks consistency of list iterator without moving the cursor.
protected  void assertUnmodifying()
          Calls all modifying methods of the underlying iterator and checks if they throw an UnsupportedOperationException.
protected  void checkConsistency()
          This method is called at the start of the test cycle and after each modification of the test object.
protected  void modifyAtStartTest()
          Asserts that a call of set before next throws an IllegalStateException.
protected static
<E> ListIteratorTest<ListIterator<E>,E>
newInstance(List<E> list)
          Creates a new test from the specified base list.
protected static
<E> ListIteratorTest<ListIterator<E>,E>
newInstance(List<E> list, int index)
          Creates a new test from the specified base list.
protected  void performCycle()
          Calls set, remove and add.
protected  void readTest()
          Performs all tests that do not change the collection underlying the iterator.
 
Methods inherited from class net.sf.molae.pipe.test.IteratorTest
getInstance
 
Methods inherited from class net.sf.molae.pipe.test.ObjectTest
assertFalse, assertTestValuesSet, getTestObject, setTestValuesSet, toString
 
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListIteratorTest

protected ListIteratorTest(B testObject,
                           List<E> list,
                           int index)
Creates a new test with the specified candidate.

Parameters:
testObject - the candidate of the test
Throws:
NullPointerException - if the specified test objects is null.
Method Detail

newInstance

protected static <E> ListIteratorTest<ListIterator<E>,E> newInstance(List<E> list)
Creates a new test from the specified base list.

Parameters:
list - the base list of the list iterator to test
Throws:
NullPointerException - if the specified test objects is null.

newInstance

protected static <E> ListIteratorTest<ListIterator<E>,E> newInstance(List<E> list,
                                                                     int index)
Creates a new test from the specified base list.

Parameters:
list - the base list of the list iterator to test
index - index of first element to be returned from the list iterator (by a call to the next method).
Throws:
IndexOutOfBoundsException - index < 0 || index > size() of base list.
NullPointerException - if the specified test objects is null.

assertConsistency

public void assertConsistency()
Checks consistency of list iterator without moving the cursor.

Overrides:
assertConsistency in class ObjectTest<B extends ListIterator<E>>
Throws:
AssertionFailedError - if the test object does not pass the test.

assertUnmodifying

protected void assertUnmodifying()
Calls all modifying methods of the underlying iterator and checks if they throw an UnsupportedOperationException.

Overrides:
assertUnmodifying in class IteratorTest<B extends ListIterator<E>>
Throws:
AssertionFailedError - if any of the called operations did not throw an UnsupportedOperationException

readTest

protected void readTest()
Description copied from class: IteratorTest
Performs all tests that do not change the collection underlying the iterator. For a simple iterator this is testing that trying to call next at the end throws an NoSuchElementException.

Overrides:
readTest in class IteratorTest<B extends ListIterator<E>>

checkConsistency

protected void checkConsistency()
This method is called at the start of the test cycle and after each modification of the test object. This implementation calls readTest().

Throws:
AssertionFailedError - if the test object is not consistent.

performCycle

protected void performCycle()
Calls set, remove and add.

Throws:
AssertionFailedError - if the test object is not consistent.
UnsupportedOperationException - if any of the called methods is not implemented.

modifyAtStartTest

protected void modifyAtStartTest()
Asserts that a call of set before next throws an IllegalStateException.

Overrides:
modifyAtStartTest in class IteratorTest<B extends ListIterator<E>>
Throws:
AssertionFailedError - if the test object does not pass the test.