Tests base
java.util.Map methods and contracts.
The forces at work here are similar to those in
TestCollection .
If your class implements the full Map interface, including optional
operations, simply extend this class, and implement the
TestMap.makeEmptyMap() method.
On the other hand, if your map implemenation is wierd, you may have to
override one or more of the other protected methods. They're described
below.
Entry Population Methods
Override these methods if your map requires special entries:
Supported Operation Methods
Override these methods if your map doesn't support certain operations:
Fixture Methods
For tests on modification operations (puts and removes), fixtures are used
to verify that that operation results in correct state for the map and its
collection views. Basically, the modification is performed against your
map implementation, and an identical modification is performed against
a confirmed map implementation. A confirmed map implementation is
something like java.util.HashMap , which is known to conform
exactly to the
Map contract. After the modification takes place
on both your map implementation and the confirmed map implementation, the
two maps are compared to see if their state is identical. The comparison
also compares the collection views to make sure they're still the same.
The upshot of all that is that any test that modifies the map in
any way will verify that all of the map's state is still
correct, including the state of its collection views. So for instance
if a key is removed by the map's key set's iterator, then the entry set
is checked to make sure the key/value pair no longer appears.
The
TestMap.map field holds an instance of your collection implementation.
The
TestMap.entrySet ,
TestMap.keySet and
TestMap.collectionValues fields hold
that map's collection views. And the
TestMap.confirmed field holds
an instance of the confirmed collection implementation. The
TestMap.resetEmpty() and
TestMap.resetFull() methods set these fields to
empty or full maps, so that tests can proceed from a known state.
After a modification operation to both
TestMap.map and
TestMap.confirmed ,
the
TestMap.verify() method is invoked to compare the results. The
* verify() method calls separate methods to verify the map and its three
collection views (
verifyMap(),
verifyEntrySet() ,
* verifyKeySet() , and
verifyValues() ). You may want to override one
of the verification methodsto perform additional verifications. For
instance,
TestDoubleOrderedMap would want override its
TestMap.verifyValues() method to verify that the values are unique and in
ascending order.
Other Notes
If your
Map fails one of these tests by design, you may still use
this base set of cases. Simply override the test case (method) your
Map fails and/or the methods that define the assumptions used by the test
cases. For example, if your map does not allow duplicate values, override
TestMap.useDuplicateValues() and have it return false
author: Michael Smith author: Rodney Waldhoff author: Paul Jack version: $Id: TestMap.java,v 1.20.2.1 2004/05/22 12:14:05 scolebourne Exp $ |