net.sf.molae.pipe.test
Class MapTest<B extends Map<K,V>,K,V>

java.lang.Object
  extended by org.junit.Assert
      extended by net.sf.molae.pipe.test.ObjectTest<B>
          extended by net.sf.molae.pipe.test.MapTest<B,K,V>
Direct Known Subclasses:
SortedMapTest

public class MapTest<B extends Map<K,V>,K,V>
extends ObjectTest<B>

Test methods to check the contract of map implementing classes.


Field Summary
protected  AbstractTransformer<Map.Entry<K,?>,K> TO_KEY_TRANSFORMER
          Transforms a map entry to its key.
protected  AbstractTransformer<Map.Entry<?,V>,V> TO_VALUE_TRANSFORMER
          Transforms a map entry to its value.
 
Constructor Summary
protected MapTest(B testObject)
          Creates a new test with the specified candidate.
 
Method Summary
 void assertConsistency()
          Checks consistency of all reading map methods.
 void assertImmutablity()
          Calls all modifying methods of the underlying map and checks if they throw an UnsupportedOperationException.
protected  void checkConsistency()
          This method is called at the start of the test cycle and after each modification of the test object.
static
<K,V> MapTest<Map<K,V>,K,V>
getInstance(Map<K,V> testObject)
          Creates a new instance of this class with the specified testObject as test object.
protected  void performBulkCycle()
          Method to test putAll.
 void performCycle()
          Performs a test cycle that uses modifying methods but is expected to leave the test object in an equal state as at the start - if everything works fine.
protected  void performCycle(K key, V subst)
          Performs a test cycle for the specified key.
 void performIntegerTest()
          Deprecated. Use setIntegerTestValues(net.sf.molae.pipe.test.MapTest) and performValuesTest() instead.
 void performValuesTest()
          Method to test map implementations that support integers.
static void setIntegerTestValues(MapTest<?,? super Integer,? super Integer> test)
           
 void setTestValues(V elem1, V elem2, V elem3, K key1, K key2, K key3)
          Defines the test data to be used in performValuesTest().
 
Methods inherited from class net.sf.molae.pipe.test.ObjectTest
assertFalse, assertTestValuesSet, getTestObject, setTestValuesSet, toString
 
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TO_KEY_TRANSFORMER

protected final AbstractTransformer<Map.Entry<K,?>,K> TO_KEY_TRANSFORMER
Transforms a map entry to its key.


TO_VALUE_TRANSFORMER

protected final AbstractTransformer<Map.Entry<?,V>,V> TO_VALUE_TRANSFORMER
Transforms a map entry to its value.

Constructor Detail

MapTest

protected MapTest(B testObject)
Creates a new test with the specified candidate.

Parameters:
testObject - the candidate of the test
Throws:
NullPointerException - if the specified test objects is null.
Method Detail

getInstance

public static final <K,V> MapTest<Map<K,V>,K,V> getInstance(Map<K,V> testObject)
Creates a new instance of this class with the specified testObject as test object.

Parameters:
testObject - the candidate of the test
Returns:
an instance of this class with the specified testObject as test object.
Throws:
NullPointerException - if the specified test objects is null.

assertConsistency

public void assertConsistency()
Checks consistency of all reading map methods.

Overrides:
assertConsistency in class ObjectTest<B extends Map<K,V>>
Throws:
AssertionFailedError - if the map contract is broken by the tested map.

assertImmutablity

public void assertImmutablity()
Calls all modifying methods of the underlying map and checks if they throw an UnsupportedOperationException.

Throws:
AssertionFailedError - if any of the called operations did not throw an UnsupportedOperationException

checkConsistency

protected void checkConsistency()
This method is called at the start of the test cycle and after each modification of the test object. This implementation calls assertConsistency().

Throws:
AssertionFailedError - if the test object is not consistent.

performCycle

protected void performCycle(K key,
                            V subst)
Performs a test cycle for the specified key.

Parameters:
key - the key of the map entry for which the cycle is performed
subst - the value to which the map entry value is set during the cycle
Throws:
AssertionFailedError - if the map contract is broken by the tested map.
UnsupportedOperationException - if any of the called methods is not implemented.

performBulkCycle

protected void performBulkCycle()
Method to test putAll.

Throws:
AssertionFailedError - if the map contract is broken by the tested map.
UnsupportedOperationException - if putAll is not implemented.

performCycle

public void performCycle()
Performs a test cycle that uses modifying methods but is expected to leave the test object in an equal state as at the start - if everything works fine.

Throws:
AssertionFailedError - if the map contract is broken by the tested map.
UnsupportedOperationException - if any of the called methods is not implemented.

setTestValues

public void setTestValues(V elem1,
                          V elem2,
                          V elem3,
                          K key1,
                          K key2,
                          K key3)
Defines the test data to be used in performValuesTest().


setIntegerTestValues

public static void setIntegerTestValues(MapTest<?,? super Integer,? super Integer> test)

performValuesTest

public void performValuesTest()
Method to test map implementations that support integers. Fills the specified map with three entries and compares it to a HashMap with the same entries.

Throws:
AssertionFailedError - if the test object does not pass the test.
IllegalStateException - if test values have not been set.

performIntegerTest

public void performIntegerTest()
Deprecated. Use setIntegerTestValues(net.sf.molae.pipe.test.MapTest) and performValuesTest() instead.

Method to test map implementations that support integers.