Class AbstractTestSet

  • All Implemented Interfaces:
    java.lang.Cloneable, junit.framework.Test
    Direct Known Subclasses:
    AbstractTestMap.TestMapEntrySet, AbstractTestMap.TestMapKeySet, AbstractTestSortedSet

    public abstract class AbstractTestSet
    extends AbstractTestCollection
    Abstract test class for Set methods and contracts.

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

    To use, subclass and override the 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 AbstractTestCollection for more details.

    Since:
    Commons Collections 3.0
    • Constructor Detail

      • AbstractTestSet

        public AbstractTestSet​(java.lang.String name)
        JUnit constructor.
        Parameters:
        name - name for test
    • Method Detail

      • makeConfirmedCollection

        public java.util.Collection makeConfirmedCollection()
        Returns an empty Set for use in modification testing.
        Specified by:
        makeConfirmedCollection in class AbstractTestCollection
        Returns:
        a confirmed empty collection
      • makeConfirmedFullCollection

        public java.util.Collection makeConfirmedFullCollection()
        Returns a full Set for use in modification testing.
        Specified by:
        makeConfirmedFullCollection in class AbstractTestCollection
        Returns:
        a confirmed full collection
      • makeEmptySet

        public abstract java.util.Set makeEmptySet()
        Makes an empty set. The returned set should have no elements.
        Returns:
        an empty set
      • makeFullSet

        public java.util.Set makeFullSet()
        Makes a full set by first creating an empty set and then adding all the elements returned by AbstractTestCollection.getFullElements(). Override if your set does not support the add operation.
        Returns:
        a full set
      • testSetEquals

        public void testSetEquals()
        Tests Set.equals(Object).
      • testSetHashCode

        public void testSetHashCode()
        Tests Set.hashCode().