Keel 2.1RC2

org.apache.commons.collections
Class TestSet

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.commons.collections.BulkTest
              extended byorg.apache.commons.collections.TestObject
                  extended byorg.apache.commons.collections.TestCollection
                      extended byorg.apache.commons.collections.TestSet
All Implemented Interfaces:
java.lang.Cloneable, junit.framework.Test
Direct Known Subclasses:
TestMap.TestMapEntrySet, TestMap.TestMapKeySet

public abstract class TestSet
extends TestCollection

Tests base 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() 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 TestCollection for more details.

Version:
$Id: TestSet.java,v 1.2 2002/06/18 03:06:45 mas Exp $
Author:
Paul Jack

Field Summary
 
Fields inherited from class org.apache.commons.collections.TestCollection
collection, confirmed
 
Fields inherited from class org.apache.commons.collections.TestObject
COLLECTIONS_MAJOR_VERSION
 
Fields inherited from class org.apache.commons.collections.BulkTest
verboseName
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
TestSet(java.lang.String name)
          Constructor.
 
Method Summary
protected  java.util.Set getConfirmedSet()
          Return the TestCollection.confirmed fixture, but cast as a Set.
protected  java.util.Set getSet()
          Return the TestCollection.collection fixture, but cast as a Set.
protected  java.util.Collection makeCollection()
          Makes an empty collection by invoking makeEmptySet().
protected  java.util.Collection makeConfirmedCollection()
          Returns an empty HashSet for use in modification testing.
protected  java.util.Collection makeConfirmedFullCollection()
          Returns a full HashSet for use in modification testing.
protected abstract  java.util.Set makeEmptySet()
          Makes an empty set.
protected  java.util.Collection makeFullCollection()
          Makes a full collection by invoking makeFullSet().
protected  java.util.Set makeFullSet()
          Makes a full set by first creating an empty set and then adding all the elements returned by TestCollection.getFullElements().
 void testSetEquals()
          Tests Set.equals(Object).
 void testSetHashCode()
          Tests Set.hashCode().
protected  void verify()
          Provides additional verifications for sets.
 
Methods inherited from class org.apache.commons.collections.TestCollection
areEqualElementsDistinguishable, getFullElements, getFullNonNullElements, getFullNonNullStringElements, getOtherElements, getOtherNonNullElements, getOtherNonNullStringElements, isAddSupported, isRemoveSupported, makeObject, resetEmpty, resetFull, testCollectionAdd, testCollectionAddAll, testCollectionClear, testCollectionContains, testCollectionContainsAll, testCollectionIsEmpty, testCollectionIterator, testCollectionIteratorFailFast, testCollectionIteratorRemove, testCollectionRemove, testCollectionRemoveAll, testCollectionRetainAll, testCollectionSize, testCollectionToArray, testCollectionToArray2, testCollectionToString, testUnsupportedAdd, testUnsupportedRemove
 
Methods inherited from class org.apache.commons.collections.TestObject
getCanonicalEmptyCollectionName, getCanonicalFullCollectionName, getCompatibilityVersion, readExternalFormFromBytes, readExternalFormFromDisk, supportsEmptyCollections, supportsFullCollections, testCanonicalEmptyCollectionExists, testCanonicalFullCollectionExists, testObjectEqualsSelf, testObjectHashCodeEqualsContract, testObjectHashCodeEqualsSelfHashCode, testSimpleSerialization, writeExternalFormToBytes, writeExternalFormToDisk
 
Methods inherited from class org.apache.commons.collections.BulkTest
clone, ignoredSimpleTests, makeSuite, toString
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, name, run, run, runBare, runTest, setName, setUp, tearDown
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestSet

public TestSet(java.lang.String name)
Constructor.

Parameters:
name - name for test
Method Detail

makeCollection

protected final java.util.Collection makeCollection()
Makes an empty collection by invoking makeEmptySet().

Specified by:
makeCollection in class TestCollection
Returns:
an empty collection

makeFullCollection

protected final java.util.Collection makeFullCollection()
Makes a full collection by invoking makeFullSet().

Overrides:
makeFullCollection in class TestCollection
Returns:
a full collection

getSet

protected java.util.Set getSet()
Return the TestCollection.collection fixture, but cast as a Set.


makeConfirmedCollection

protected java.util.Collection makeConfirmedCollection()
Returns an empty HashSet for use in modification testing.

Specified by:
makeConfirmedCollection in class TestCollection
Returns:
a confirmed empty collection

makeConfirmedFullCollection

protected java.util.Collection makeConfirmedFullCollection()
Returns a full HashSet for use in modification testing.

Specified by:
makeConfirmedFullCollection in class TestCollection
Returns:
a confirmed full collection

getConfirmedSet

protected java.util.Set getConfirmedSet()
Return the TestCollection.confirmed fixture, but cast as a Set.


makeEmptySet

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

Returns:
an empty set

makeFullSet

protected java.util.Set makeFullSet()
Makes a full set by first creating an empty set and then adding all the elements returned by TestCollection.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().


verify

protected void verify()
Provides additional verifications for sets.

Overrides:
verify in class TestCollection

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.