|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.junit.Assert
net.sf.molae.pipe.test.ObjectTest<B>
net.sf.molae.pipe.test.CollectionTest<B,E>
public class CollectionTest<B extends Collection<E>,E>
Test methods to check the contract of collection implementing classes.
| Constructor Summary | |
|---|---|
protected |
CollectionTest(B testObject)
Creates a new test with the specified candidate. |
| Method Summary | ||
|---|---|---|
protected void |
assertAddProhibited()
This method asserts that that the specifed collection does not implement add or
addAll. |
|
void |
assertConsistency()
Checks consistency of all reading collection methods. |
|
void |
assertEqualContent(String message,
Collection<?> col)
Checks if the specified collection has the same elements as the tested collection. |
|
static void |
assertEqualSequence(String message,
Iterator expected,
Iterator actual)
Compares the specified iterators. |
|
void |
assertImmutability()
Calls all modifying methods of the underlying collection and checks if they throw an UnsupportedOperationException. |
|
protected void |
assertValidArray(String message,
Object[] a)
Checks if the specified array is a valid result of the toArray() or
toArray(Object[])
operation, respectively. |
|
protected void |
checkAddAll(String message,
List<E> l)
This method is used to check the result of an addAll() call on an empty
collection. |
|
protected void |
checkConsistency()
This method is called at the start of the test cycle and after each modification of the test object. |
|
static
|
getInstance(Collection<E> testObject)
Creates a new instance of this class with the specified testObject as test object. |
|
protected E |
getTestValue()
Provides a value of the element type. |
|
protected void |
performBulkCycle()
Performs a test cycle of methods that take collections as argument ( Collection.removeAll(Collection),
Collection.retainAll(Collection) and
Collection.addAll(Collection)). |
|
void |
performCycle()
Performs a test cycle that uses modifying methods but is expected to leave the test object in an equal state as at the start - if everything works fine. |
|
void |
performIntegerTest()
Deprecated. Use setIntegerTestValues(net.sf.molae.pipe.test.CollectionTest, ? super java.lang.Integer>)
and performValuesTest() instead. |
|
void |
performValuesTest()
Fills the specified collection with five elements and compares it to a ArrayList with the same elements. |
|
static void |
setIntegerTestValues(CollectionTest<?,? super Integer> test)
|
|
void |
setTestValues(E elem1,
E elem2,
E elem3,
E elem4,
E elem5)
Defines the test data to be used in performValuesTest(). |
|
| Methods inherited from class net.sf.molae.pipe.test.ObjectTest |
|---|
assertFalse, assertTestValuesSet, getTestObject, setTestValuesSet, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected CollectionTest(B testObject)
testObject - the candidate of the test
NullPointerException - if the specified test objects is
null.| Method Detail |
|---|
public static final void assertEqualSequence(String message,
Iterator expected,
Iterator actual)
message - the message to be displayed if the assertion failsexpected - expected valueactual - actual value
AssertionFailedError - if the specified iterators are not
equal in the defined way.public static final <E> CollectionTest<Collection<E>,E> getInstance(Collection<E> testObject)
testObject - the candidate of the test
NullPointerException - if the specified test objects is
null.
public final void assertEqualContent(String message,
Collection<?> col)
message - the message to be displayed if the assertion failscol - the collection to be compared
AssertionFailedError - if the specified collection and the tested
collection do not contain the same elements with the same cardinality.
protected void checkAddAll(String message,
List<E> l)
This method is used to check the result of an
addAll() call on an empty
collection.
Must be overwritten for subclasses that have a more specific contract
concerning addAll.
This implementation checks that both collections contain the other one.
message - the message to be displayed if the assertion failsl - the list to compare
AssertionFailedError - if the specified list is not equal in the
described sense.
protected void assertValidArray(String message,
Object[] a)
Checks if the specified array is a valid result of the
toArray() or
toArray(Object[])
operation, respectively.
Must be overwritten for subclasses that have a more specific contract concerning lists.
This implementatin calls
assertEqualContent(String,Collection) with a list
version of the array.
message - the message to be displayed if the assertion failsa - the result of a toArray() operation.
AssertionFailedError - if the specified array is not a valid
result.protected E getTestValue()
public void assertConsistency()
assertConsistency in class ObjectTest<B extends Collection<E>>AssertionFailedError - if the collection contract is broken by
the test object.public void assertImmutability()
UnsupportedOperationException.
AssertionFailedError - if any of the called operations
did not throw an UnsupportedOperationExceptionprotected void assertAddProhibited()
add or
addAll.
Used by MapTest.
AssertionFailedError - if the specified collection implements
an adding method.protected void checkConsistency()
assertConsistency().
AssertionFailedError - if the test object is not consistent.protected void performBulkCycle()
Collection.removeAll(Collection),
Collection.retainAll(Collection) and
Collection.addAll(Collection)).
AssertionFailedError - if the set contract is broken by
the specified set.
UnsupportedOperationException - if any of the called
methods is not implemented.public void performCycle()
performBulkCycle().
AssertionFailedError - if the test object does not pass the test.
UnsupportedOperationException - if any of the called
methods is not implemented.
public void setTestValues(E elem1,
E elem2,
E elem3,
E elem4,
E elem5)
performValuesTest().
public static void setIntegerTestValues(CollectionTest<?,? super Integer> test)
public void performValuesTest()
ArrayList with the same elements.
AssertionFailedError - if the test object does not pass the test.
IllegalStateException - if test values have not been set.public void performIntegerTest()
setIntegerTestValues(net.sf.molae.pipe.test.CollectionTest, ? super java.lang.Integer>)
and performValuesTest() instead.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||