Class AbstractContainerTester<C,E>
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
com.google.common.collect.testing.AbstractTester<OneSizeTestContainerGenerator<C,E>>
com.google.common.collect.testing.AbstractContainerTester<C,E>
- Type Parameters:
C- the type of the containerE- the type of the container's contents
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
AbstractCollectionTester,AbstractMapTester,AbstractMultimapTester
public abstract class AbstractContainerTester<C,E>
extends AbstractTester<OneSizeTestContainerGenerator<C,E>>
Base class for testers of classes (including
Collection and Map)
that contain elements.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Collection<E>protected AbstractContainerTester.ArrayWithDuplicate<E>protected MinimalCollection<E>protected E[]protected E[]protected final Ee0()protected final Ee1()protected final Ee2()protected final Ee3()protected final Ee4()protected MinimalCollection<E>protected final voidexpectAdded(int index, E... elements) protected final voidexpectAdded(int index, Collection<E> elements) protected final voidexpectAdded(E... elements) Asserts that the collection under test contains exactly the elements it was initialized with plus the given elements, according toexpectContents(java.util.Collection).protected final voidexpectContents(E... elements) protected voidexpectContents(Collection<E> expected) Asserts that the collection under test contains exactly the given elements, respecting cardinality but not order.protected voidexpectMissing(E... elements) protected voidprotected intprotected intReturns the sample elements as ordered byTestContainerGenerator.order(List).protected Collection<E>protected Collection<E>getSampleElements(int howMany) protected CReplaces the existing container under test with a new container created by the subject generator.protected CresetContainer(C newValue) Replaces the existing container under test with a new container.voidsetUp()Methods inherited from class com.google.common.collect.testing.AbstractTester
getName, getSubjectGenerator, getTestMethodName, init, init, tearDownMethods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, run, run, runBare, runTest, setName, toString
-
Field Details
-
samples
-
container
-
-
Constructor Details
-
AbstractContainerTester
public AbstractContainerTester()
-
-
Method Details
-
setUp
- Overrides:
setUpin classAbstractTester<OneSizeTestContainerGenerator<C,E>> - Throws:
Exception
-
actualContents
- Returns:
- the contents of the container under test, for use by
expectContents(E...)and its friends.
-
resetContainer
Replaces the existing container under test with a new container created by the subject generator.- Returns:
- the new container instance.
- See Also:
-
resetContainer
Replaces the existing container under test with a new container. This is useful when a single test method needs to create multiple containers while retaining the ability to useexpectContents(E...)and other convenience methods. The creation of multiple containers in a single method is discouraged in most cases, but it is vital to the iterator tests.- Parameters:
newValue- the new container instance- Returns:
- the new container instance
-
expectContents
- Parameters:
elements- expected contents ofcontainer- See Also:
-
expectContents
Asserts that the collection under test contains exactly the given elements, respecting cardinality but not order. Subclasses may override this method to provide stronger assertions, e.g., to check ordering in lists, but realize that unless a test extendsAbstractListTester, a call toexpectContents()invokes this version.- Parameters:
expected- expected value ofcontainer
-
expectUnchanged
protected void expectUnchanged() -
expectAdded
Asserts that the collection under test contains exactly the elements it was initialized with plus the given elements, according toexpectContents(java.util.Collection). In other words, for the defaultexpectContents()implementation, the number of occurrences of each given element has increased by one since the test collection was created, and the number of occurrences of all other elements has not changed.Note: This means that a test like the following will fail if
collectionis aSet:collection.add(existingElement); expectAdded(existingElement);
In this case,
collectionwas not modified as a result of theadd()call, and the test will fail because the number of occurrences ofexistingElementis unchanged.- Parameters:
elements- expected additional contents ofcontainer
-
expectAdded
-
expectAdded
-
expectMissing
-
createSamplesArray
-
createOrderedArray
-
createArrayWithDuplicateElement
- Returns:
- an array of the proper size with a duplicate element. The size must be at least three.
-
getNumElements
protected int getNumElements() -
getSampleElements
-
getSampleElements
-
getOrderedElements
Returns the sample elements as ordered byTestContainerGenerator.order(List). Tests should used this method only if they declare requirementCollectionFeature.KNOWN_ORDER. -
getNullLocation
protected int getNullLocation()- Returns:
- a suitable location for a null element, to use when initializing containers for tests that involve a null element being present.
-
createDisjointCollection
-
emptyCollection
-
e0
-
e1
-
e2
-
e3
-
e4
-