org.apache.commons.collections.set

Class AbstractTestSet

public abstract class AbstractTestSet extends AbstractTestCollection

Abstract test class for {@link Set} methods and contracts.

Since {@link Set} doesn't stipulate much new behavior that isn't already found in {@link Collection}, this class basically just adds tests for {@link Set#equals} and {@link Set#hashCode()} along with an updated {@link #verify()} that ensures elements do not appear more than once in the set.

To use, subclass and override the {@link #makeEmptySet()} method. You may have to override other protected methods if your set is not modifiable, or if your set restricts what kinds of elements may be added; see {@link AbstractTestCollection} for more details.

Since: Commons Collections 3.0

Constructor Summary
AbstractTestSet(String name)
JUnit constructor.
Method Summary
SetgetConfirmedSet()
Return the {@link AbstractTestCollection#confirmed} fixture, but cast as a Set.
SetgetSet()
Return the {@link AbstractTestCollection#collection} fixture, but cast as a Set.
booleanisEqualsCheckable()
Set equals method is defined.
CollectionmakeCollection()
Makes an empty collection by invoking {@link #makeEmptySet()}.
CollectionmakeConfirmedCollection()
Returns an empty Set for use in modification testing.
CollectionmakeConfirmedFullCollection()
Returns a full Set for use in modification testing.
abstract SetmakeEmptySet()
Makes an empty set.
CollectionmakeFullCollection()
Makes a full collection by invoking {@link #makeFullSet()}.
SetmakeFullSet()
Makes a full set by first creating an empty set and then adding all the elements returned by {@link #getFullElements()}.
voidtestSetEquals()
Tests {@link Set#equals(Object)}.
voidtestSetHashCode()
Tests {@link Set#hashCode()}.
voidverify()
Provides additional verifications for sets.

Constructor Detail

AbstractTestSet

public AbstractTestSet(String name)
JUnit constructor.

Parameters: name name for test

Method Detail

getConfirmedSet

public Set getConfirmedSet()
Return the {@link AbstractTestCollection#confirmed} fixture, but cast as a Set.

getSet

public Set getSet()
Return the {@link AbstractTestCollection#collection} fixture, but cast as a Set.

isEqualsCheckable

public boolean isEqualsCheckable()
Set equals method is defined.

makeCollection

public final Collection makeCollection()
Makes an empty collection by invoking {@link #makeEmptySet()}.

Returns: an empty collection

makeConfirmedCollection

public Collection makeConfirmedCollection()
Returns an empty Set for use in modification testing.

Returns: a confirmed empty collection

makeConfirmedFullCollection

public Collection makeConfirmedFullCollection()
Returns a full Set for use in modification testing.

Returns: a confirmed full collection

makeEmptySet

public abstract Set makeEmptySet()
Makes an empty set. The returned set should have no elements.

Returns: an empty set

makeFullCollection

public final Collection makeFullCollection()
Makes a full collection by invoking {@link #makeFullSet()}.

Returns: a full collection

makeFullSet

public Set makeFullSet()
Makes a full set by first creating an empty set and then adding all the elements returned by {@link #getFullElements()}. Override if your set does not support the add operation.

Returns: a full set

testSetEquals

public void testSetEquals()
Tests {@link Set#equals(Object)}.

testSetHashCode

public void testSetHashCode()
Tests {@link Set#hashCode()}.

verify

public void verify()
Provides additional verifications for sets.
Copyright © 2001-2007 Apache Software Foundation. All Rights Reserved.