public abstract class AbstractCollectionTest extends Object
In general there are not many implementations of Collection directly, but two common constructors are the zero argument constructor and a constructor that takes another Collection. Subclasses of this class must implement the methods that create these
Modifier and Type | Field and Description |
---|---|
protected static String |
FIVE |
protected static String |
FOUR |
protected static String |
ONE |
protected static String |
THREE |
protected static String |
TWO |
Constructor and Description |
---|
AbstractCollectionTest() |
Modifier and Type | Method and Description |
---|---|
protected abstract Collection |
createCollection()
Subclasses must override this method in order to construct
an empty Collection with the null argument constructor.
|
protected abstract Collection |
createCollection(Collection input)
Subclasses must override this method in order to construct
a Collection with the elements found in the input Collection.
|
protected boolean |
doesCollectionAllowNullElements()
Subclasses should override this method if their Collection
implementation does not support null as an element in
their Collection.
|
protected boolean |
doesCollectionDelegateFromOriginalCollection()
Subclasses should override this method if their Collection
implementation delegates to the passed in collection.
|
protected boolean |
doesCollectionsIteratorSupportRemove()
Subclasses should override this method if the
Iterator returned from this collection does not
support the optional remove operation
|
protected boolean |
doesCollectionSupportDuplicateElements()
Subclasses should override this method if their Collection
implementation does not support duplicate elements.
|
protected boolean |
doesCollectionSupportEmpty()
Subclasses should override this method if their Collection
does not support the optional empty method.
|
protected boolean |
doesCollectionSupportRemove()
Subclasses should override this method if their Collection
does not support the optional remove method.
|
protected boolean |
doesCollectionSupportRetainAll()
Subclasses should override this method if their Collection
does not support the optional retainAll method.
|
protected TestCollectionElement |
getElement(String data)
This returns an implementation of TestCollectionElement that
will be put into the Collection implementation.
|
protected boolean |
isCollectionArgumentConstructorSupported()
Subclasses should override this method if their Collection
implementation does not support a Collection argument
constructor.
|
protected boolean |
isNullArgumentConstructorSupported()
Subclasses should override this method if their Collection
implementation does not support a null argument
constructor.
|
void |
testAddAllThrows()
Tests that addAll throws with null input
|
void |
testAddAllWithEmptyCollectionAndEmptyInput()
Tests that an addAll works with an empty input
|
void |
testAddAllWithNonEmptyCollectionAndEmptyInput()
Tests that an addAll works with an empty input (non empty initial collection)
|
void |
testAddAllWithNonEmptyCollectionAndNonEmptyInputDups()
Tests that an addAll works with an non empty input with duplication
|
void |
testAddAllWithNonEmptyCollectionAndNonEmptyInputNoDups()
Tests that an addAll works with an non empty input
|
void |
testAddOneThousandEntries()
Tries to test the resizing of the collection
by adding 1000 items
|
void |
testAddReturnsProperValueForDuplicateAdd()
This test ensures that add returns the proper value
|
void |
testAddReturnsProperValueForNonDuplicateAdd()
This test ensures that add returns the proper value
|
void |
testCanAddToCollection()
Tests that a single element can be added to the list
|
void |
testCanCollectionHaveNullAndNonNullElements()
Tests that lists can have null elements interspersed
with non-null elements
|
void |
testCanCollectionHaveNullElements()
Tests that the collection functions properly with
a null element added
|
void |
testClearWorksOnEmptyCollection()
Makes sure clear works on an already empty collection
|
void |
testClearWorksOnNonEmptyCollection()
Makes sure clear works on an already empty collection
|
void |
testCollectionFromCollectionConstructorHasZeroSize()
Tests that a list constructed from the empty collection
constructor has size zero
|
void |
testCollectionFromNullConstructorHasZeroSize()
Tests that a list constructed from the null constructor has
size zero
|
void |
testCollectionToArrayWithArgumentWithCollectionOfMultipleItems()
Tests that toArray works on an multi-valued
collection.
|
void |
testCollectionToArrayWithArgumentWithCollectionOfOneItem()
Tests that toArray works on an empty collection
|
void |
testCollectionToArrayWithArgumentWithEmptyCollection()
Tests that toArray works on an empty collection
|
void |
testCollectionToArrayWithArgumentWithNullThrows()
Tests that toArray works on an multi-valued
collection.
|
void |
testCollectionToArrayWithCollectionOfMultipleItems()
Tests that toArray works on an multi-valued
collection.
|
void |
testCollectionToArrayWithCollectionOfOneItem()
Tests that toArray works on an empty collection
|
void |
testCollectionToArrayWithEmptyCollection()
Tests that toArray works on an empty collection
|
void |
testContainsAfterAdd()
Tests that contains works properly
|
void |
testContainsAllThrows()
Tests that an containsAll works with an non empty input for
which the list does not contain at least one of the things
|
void |
testContainsAllWithEmptyCollectionAndEmptyInput()
Tests that an empty containsAll works on an empty list
|
void |
testContainsAllWithNonEmptyCollectionAndCorrectInput()
Tests that an containsAll works with an non empty input
|
void |
testContainsAllWithNonEmptyCollectionAndEmptyInput()
Tests that an containsAll works with an empty input
|
void |
testContainsAllWithNonEmptyCollectionAndIncorrectInput()
Tests that an containsAll works with an non empty input for
which the list does not contain at least one of the things
|
void |
testDoubleIteratorRemoveThrows()
Tests that removing an element from an
iterator with a single element works
|
void |
testFallingOffEndOfEmptyIteratorThrows()
Tests that calling next off an empty
iterator throws the proper exception
|
void |
testFallingOffEndOfNonEmptyIteratorThrows()
Tests that the iterator from a non-empty list works
|
void |
testIteratorRemoveOnEmptyIteratorThrows()
Tests that an iterator from a Collection with
more than one element can remove the proper
values.
|
void |
testIteratorReturnedFromEmptyList()
Tests that the iterator from an empty list works
|
void |
testListColnstructedWithNullCollectionThrows()
Tests that a list constructed from the empty collection
constructor has size zero
|
void |
testModifyingOriginalCollectionDoesNotAffectNewCollection()
Tests that modifying the elements in the original collection
do not affect the elements in the newly created collection
|
void |
testMultipleItemIterator()
Tests that an iterator from a Collection with
more than one element returns the proper values.
|
void |
testMultipleItemIteratorRemoval()
Tests that an iterator from a Collection with
more than one element can remove the proper
values.
|
void |
testRemoveAllThrows()
Tests that removeAll throws an NPE when given null
|
void |
testRemoveAllWithEmptyCollectionAndEmptyInput()
Tests that an removaAll works with an empty input
|
void |
testRemoveAllWithNonEmptyCollectionAndEmptyInput()
Tests that an removeAll works with an empty input (non-empty collection)
|
void |
testRemoveAllWithNonEmptyCollectionAndNonEmptyInput()
Tests that an removeAll works with an non empty input and non
empty set of things to remove
|
void |
testRemoveAllWithNonEmptyCollectionAndNonEmptyInputWithExtras()
Tests that an removeAll works with an non empty input and non
empty set of things to remove and the set has some extra elements
not in the original set
|
void |
testRemoveFirstThingFromMultiElementList()
This test ensures that remove can remove the
first item added to the collection
|
void |
testRemoveFromEmptyList()
This test ensures that remove works properly in an empty list
|
void |
testRemoveFromOneElementList()
This test ensures that remove returns the proper value
|
void |
testRemoveLastThingFromMultiElementList()
This test ensures that remove can remove the
last item added to the collection
|
void |
testRemoveMiddleThingFromMultiElementList()
This test ensures that remove can remove a
first item added to the collection
|
void |
testRetainAllThrows()
Tests that retainAll throws an NPE when given null
|
void |
testRetainAllWithEmptyCollectionAndEmptyInput()
Tests that an retainAll works with an empty input
|
void |
testRetainAllWithNonEmptyCollectionAndEmptyInput()
Tests that an retainAll works with an empty input (non-empty collection)
|
void |
testRetainAllWithNonEmptyCollectionAndNonEmptyInput()
Tests that an retainAll works with an non empty input and non
empty set of things to retain
|
void |
testRetainAllWithNonEmptyCollectionAndNonEmptyInputWithExtras()
Tests that an retainAll works with an non empty input and non
empty set of things to remove and the set has some extra elements
not in the original set
|
void |
testSingleItemIterator()
Tests that an iterator from a list with
one element returns the proper values
|
void |
testSingleItemIteratorRemoval()
Tests that removing an element from an
iterator with a single element works
|
void |
testUnsupporedRemoveIteratorThrows()
Tests that removing an element from an
iterator with a single element works
|
void |
testUnsupportedClearThrows()
Tests that if you do NOT support empty that
you throw
|
void |
testUnsupportedRetainAllThrowsProperException()
Tests that retainAll throws an NPE when given null
|
protected static final String ONE
protected static final String TWO
protected static final String THREE
protected static final String FOUR
protected static final String FIVE
protected boolean isNullArgumentConstructorSupported()
protected boolean isCollectionArgumentConstructorSupported()
protected boolean doesCollectionDelegateFromOriginalCollection()
protected boolean doesCollectionAllowNullElements()
protected boolean doesCollectionSupportDuplicateElements()
protected boolean doesCollectionSupportRemove()
protected boolean doesCollectionSupportEmpty()
protected boolean doesCollectionsIteratorSupportRemove()
protected boolean doesCollectionSupportRetainAll()
protected abstract Collection createCollection()
protected abstract Collection createCollection(Collection input)
input
- A possibly null and possibly empty collection of items
to seed the list withprotected TestCollectionElement getElement(String data)
data
- The string that must be returned via the listElementReturn
methodpublic void testCollectionFromNullConstructorHasZeroSize()
public void testCollectionFromCollectionConstructorHasZeroSize()
public void testListColnstructedWithNullCollectionThrows()
public void testCanAddToCollection()
public void testModifyingOriginalCollectionDoesNotAffectNewCollection()
public void testContainsAfterAdd()
public void testCanCollectionHaveNullElements()
public void testCanCollectionHaveNullAndNonNullElements()
public void testIteratorReturnedFromEmptyList()
public void testSingleItemIterator()
public void testMultipleItemIterator()
public void testFallingOffEndOfEmptyIteratorThrows()
public void testFallingOffEndOfNonEmptyIteratorThrows()
public void testSingleItemIteratorRemoval()
public void testMultipleItemIteratorRemoval()
public void testIteratorRemoveOnEmptyIteratorThrows()
public void testDoubleIteratorRemoveThrows()
public void testUnsupporedRemoveIteratorThrows()
public void testCollectionToArrayWithEmptyCollection()
public void testCollectionToArrayWithCollectionOfOneItem()
public void testCollectionToArrayWithCollectionOfMultipleItems()
public void testCollectionToArrayWithArgumentWithEmptyCollection()
public void testCollectionToArrayWithArgumentWithCollectionOfOneItem()
public void testCollectionToArrayWithArgumentWithCollectionOfMultipleItems()
public void testCollectionToArrayWithArgumentWithNullThrows()
public void testAddReturnsProperValueForNonDuplicateAdd()
public void testAddReturnsProperValueForDuplicateAdd()
public void testRemoveFromEmptyList()
public void testRemoveFromOneElementList()
public void testRemoveFirstThingFromMultiElementList()
public void testRemoveLastThingFromMultiElementList()
public void testRemoveMiddleThingFromMultiElementList()
public void testContainsAllWithEmptyCollectionAndEmptyInput()
public void testContainsAllWithNonEmptyCollectionAndEmptyInput()
public void testContainsAllWithNonEmptyCollectionAndCorrectInput()
public void testContainsAllWithNonEmptyCollectionAndIncorrectInput()
public void testContainsAllThrows()
public void testAddAllWithEmptyCollectionAndEmptyInput()
public void testAddAllWithNonEmptyCollectionAndEmptyInput()
public void testAddAllWithNonEmptyCollectionAndNonEmptyInputNoDups()
public void testAddAllWithNonEmptyCollectionAndNonEmptyInputDups()
public void testAddAllThrows()
public void testRemoveAllWithEmptyCollectionAndEmptyInput()
public void testRemoveAllWithNonEmptyCollectionAndEmptyInput()
public void testRemoveAllWithNonEmptyCollectionAndNonEmptyInput()
public void testRemoveAllWithNonEmptyCollectionAndNonEmptyInputWithExtras()
public void testRemoveAllThrows()
public void testRetainAllWithEmptyCollectionAndEmptyInput()
public void testRetainAllWithNonEmptyCollectionAndEmptyInput()
public void testRetainAllWithNonEmptyCollectionAndNonEmptyInput()
public void testRetainAllWithNonEmptyCollectionAndNonEmptyInputWithExtras()
public void testRetainAllThrows()
public void testUnsupportedRetainAllThrowsProperException()
public void testClearWorksOnEmptyCollection()
public void testClearWorksOnNonEmptyCollection()
public void testUnsupportedClearThrows()
public void testAddOneThousandEntries()
Copyright © 2009-2017, Oracle and/or its affiliates. All Rights Reserved.