com.google.common.collect.testing
Class MapInterfaceTest<K,V>

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by com.google.common.collect.testing.MapInterfaceTest<K,V>
Type Parameters:
K - the type of keys used by the maps under test
V - the type of mapped values used the maps under test
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
ConcurrentMapInterfaceTest, SortedMapInterfaceTest

@GwtCompatible
public abstract class MapInterfaceTest<K,V>
extends junit.framework.TestCase

Tests representing the contract of Map. Concrete subclasses of this base class test conformance of concrete Map subclasses to that contract. TODO: Descriptive assertion messages, with hints as to probable fixes. TODO: Add another constructor parameter indicating whether the class under test is ordered, and check the order if so. TODO: Refactor to share code with SetTestBuilder &c.

This class is GWT compatible.

Author:
George van den Driessche

Field Summary
protected  boolean allowsNullKeys
           
protected  boolean allowsNullValues
           
protected  boolean supportsClear
           
protected  boolean supportsIteratorRemove
           
protected  boolean supportsPut
           
protected  boolean supportsRemove
           
 
Constructor Summary
protected MapInterfaceTest(boolean allowsNullKeys, boolean allowsNullValues, boolean supportsPut, boolean supportsRemove, boolean supportsClear)
          Constructor that assigns supportsIteratorRemove the same value as supportsRemove.
protected MapInterfaceTest(boolean allowsNullKeys, boolean allowsNullValues, boolean supportsPut, boolean supportsRemove, boolean supportsClear, boolean supportsIteratorRemove)
          Constructor with an explicit supportsIteratorRemove parameter.
 
Method Summary
protected  void assertInvariants(Map<K,V> map)
          Checks all the properties that should always hold of a map.
protected  void assertMoreInvariants(Map<K,V> map)
          Override this to check invariants which should hold true for a particular implementation, but which are not generally applicable to every instance of Map.
protected abstract  K getKeyNotInPopulatedMap()
          Creates a new key that is not expected to be found in makePopulatedMap().
protected abstract  V getValueNotInPopulatedMap()
          Creates a new value that is not expected to be found in makePopulatedMap().
protected  Map<K,V> makeEitherMap()
          Used by tests that require a map, but don't care whether it's populated or not.
protected abstract  Map<K,V> makeEmptyMap()
          Creates a new, empty instance of the class under test.
protected abstract  Map<K,V> makePopulatedMap()
          Creates a new, non-empty instance of the class under test.
protected  boolean supportsValuesHashCode(Map<K,V> map)
           
 void testClear()
           
 void testContainsKey()
           
 void testContainsValue()
           
 void testEntrySet()
           
 void testEntrySetAddAndAddAll()
           
 void testEntrySetClear()
           
 void testEntrySetContainsEntryIncompatibleKey()
           
 void testEntrySetContainsEntryNullKeyMissing()
           
 void testEntrySetContainsEntryNullKeyPresent()
           
 void testEntrySetForEmptyMap()
           
 void testEntrySetIteratorRemove()
           
 void testEntrySetRemove()
           
 void testEntrySetRemoveAll()
           
 void testEntrySetRemoveAllNullFromEmpty()
           
 void testEntrySetRemoveDifferentValue()
           
 void testEntrySetRemoveMissingKey()
           
 void testEntrySetRemoveNullKeyMissing()
           
 void testEntrySetRemoveNullKeyPresent()
           
 void testEntrySetRetainAll()
           
 void testEntrySetRetainAllNullFromEmpty()
           
 void testEntrySetSetValue()
           
 void testEntrySetSetValueSameValue()
           
 void testEqualsForEmptyMap()
           
 void testEqualsForEqualMap()
           
 void testEqualsForLargerMap()
           
 void testEqualsForSmallerMap()
           
 void testGet()
           
 void testGetForEmptyMap()
           
 void testGetNull()
           
 void testHashCode()
           
 void testHashCodeForEmptyMap()
           
 void testKeySetClear()
           
 void testKeySetRemove()
           
 void testKeySetRemoveAll()
           
 void testKeySetRemoveAllNullFromEmpty()
           
 void testKeySetRetainAll()
           
 void testKeySetRetainAllNullFromEmpty()
           
 void testPutAllExistingKey()
           
 void testPutAllNewKey()
           
 void testPutExistingKey()
           
 void testPutNewKey()
           
 void testPutNullKey()
           
 void testPutNullValue()
           
 void testPutNullValueForExistingKey()
           
 void testRemove()
           
 void testRemoveMissingKey()
           
 void testSize()
           
 void testValues()
           
 void testValuesClear()
           
 void testValuesIteratorRemove()
           
 void testValuesRemove()
           
 void testValuesRemoveAll()
           
 void testValuesRemoveAllNullFromEmpty()
           
 void testValuesRemoveMissing()
           
 void testValuesRetainAll()
           
 void testValuesRetainAllNullFromEmpty()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

supportsPut

protected final boolean supportsPut

supportsRemove

protected final boolean supportsRemove

supportsClear

protected final boolean supportsClear

allowsNullKeys

protected final boolean allowsNullKeys

allowsNullValues

protected final boolean allowsNullValues

supportsIteratorRemove

protected final boolean supportsIteratorRemove
Constructor Detail

MapInterfaceTest

protected MapInterfaceTest(boolean allowsNullKeys,
                           boolean allowsNullValues,
                           boolean supportsPut,
                           boolean supportsRemove,
                           boolean supportsClear)
Constructor that assigns supportsIteratorRemove the same value as supportsRemove.


MapInterfaceTest

protected MapInterfaceTest(boolean allowsNullKeys,
                           boolean allowsNullValues,
                           boolean supportsPut,
                           boolean supportsRemove,
                           boolean supportsClear,
                           boolean supportsIteratorRemove)
Constructor with an explicit supportsIteratorRemove parameter.

Method Detail

makeEmptyMap

protected abstract Map<K,V> makeEmptyMap()
                                  throws UnsupportedOperationException
Creates a new, empty instance of the class under test.

Returns:
a new, empty map instance.
Throws:
UnsupportedOperationException - if it's not possible to make an empty instance of the class under test.

makePopulatedMap

protected abstract Map<K,V> makePopulatedMap()
                                      throws UnsupportedOperationException
Creates a new, non-empty instance of the class under test.

Returns:
a new, non-empty map instance.
Throws:
UnsupportedOperationException - if it's not possible to make a non-empty instance of the class under test.

getKeyNotInPopulatedMap

protected abstract K getKeyNotInPopulatedMap()
                                      throws UnsupportedOperationException
Creates a new key that is not expected to be found in makePopulatedMap().

Returns:
a key.
Throws:
UnsupportedOperationException - if it's not possible to make a key that will not be found in the map.

getValueNotInPopulatedMap

protected abstract V getValueNotInPopulatedMap()
                                        throws UnsupportedOperationException
Creates a new value that is not expected to be found in makePopulatedMap().

Returns:
a value.
Throws:
UnsupportedOperationException - if it's not possible to make a value that will not be found in the map.

makeEitherMap

protected Map<K,V> makeEitherMap()
Used by tests that require a map, but don't care whether it's populated or not.

Returns:
a new map instance.

supportsValuesHashCode

protected final boolean supportsValuesHashCode(Map<K,V> map)

assertInvariants

protected final void assertInvariants(Map<K,V> map)
Checks all the properties that should always hold of a map. Also calls assertMoreInvariants(java.util.Map) to check invariants that are peculiar to specific implementations.

Parameters:
map - the map to check.
See Also:
assertMoreInvariants(java.util.Map)

assertMoreInvariants

protected void assertMoreInvariants(Map<K,V> map)
Override this to check invariants which should hold true for a particular implementation, but which are not generally applicable to every instance of Map.

Parameters:
map - the map whose additional invariants to check.

testClear

public void testClear()

testContainsKey

public void testContainsKey()

testContainsValue

public void testContainsValue()

testEntrySet

public void testEntrySet()

testEntrySetForEmptyMap

public void testEntrySetForEmptyMap()

testEntrySetContainsEntryIncompatibleKey

public void testEntrySetContainsEntryIncompatibleKey()

testEntrySetContainsEntryNullKeyPresent

public void testEntrySetContainsEntryNullKeyPresent()

testEntrySetContainsEntryNullKeyMissing

public void testEntrySetContainsEntryNullKeyMissing()

testEntrySetIteratorRemove

public void testEntrySetIteratorRemove()

testEntrySetRemove

public void testEntrySetRemove()

testEntrySetRemoveMissingKey

public void testEntrySetRemoveMissingKey()

testEntrySetRemoveDifferentValue

public void testEntrySetRemoveDifferentValue()

testEntrySetRemoveNullKeyPresent

public void testEntrySetRemoveNullKeyPresent()

testEntrySetRemoveNullKeyMissing

public void testEntrySetRemoveNullKeyMissing()

testEntrySetRemoveAll

public void testEntrySetRemoveAll()

testEntrySetRemoveAllNullFromEmpty

public void testEntrySetRemoveAllNullFromEmpty()

testEntrySetRetainAll

public void testEntrySetRetainAll()

testEntrySetRetainAllNullFromEmpty

public void testEntrySetRetainAllNullFromEmpty()

testEntrySetClear

public void testEntrySetClear()

testEntrySetAddAndAddAll

public void testEntrySetAddAndAddAll()

testEntrySetSetValue

public void testEntrySetSetValue()

testEntrySetSetValueSameValue

public void testEntrySetSetValueSameValue()

testEqualsForEqualMap

public void testEqualsForEqualMap()

testEqualsForLargerMap

public void testEqualsForLargerMap()

testEqualsForSmallerMap

public void testEqualsForSmallerMap()

testEqualsForEmptyMap

public void testEqualsForEmptyMap()

testGet

public void testGet()

testGetForEmptyMap

public void testGetForEmptyMap()

testGetNull

public void testGetNull()

testHashCode

public void testHashCode()

testHashCodeForEmptyMap

public void testHashCodeForEmptyMap()

testPutNewKey

public void testPutNewKey()

testPutExistingKey

public void testPutExistingKey()

testPutNullKey

public void testPutNullKey()

testPutNullValue

public void testPutNullValue()

testPutNullValueForExistingKey

public void testPutNullValueForExistingKey()

testPutAllNewKey

public void testPutAllNewKey()

testPutAllExistingKey

public void testPutAllExistingKey()

testRemove

public void testRemove()

testRemoveMissingKey

public void testRemoveMissingKey()

testSize

public void testSize()

testKeySetRemove

public void testKeySetRemove()

testKeySetRemoveAll

public void testKeySetRemoveAll()

testKeySetRetainAll

public void testKeySetRetainAll()

testKeySetClear

public void testKeySetClear()

testKeySetRemoveAllNullFromEmpty

public void testKeySetRemoveAllNullFromEmpty()

testKeySetRetainAllNullFromEmpty

public void testKeySetRetainAllNullFromEmpty()

testValues

public void testValues()

testValuesIteratorRemove

public void testValuesIteratorRemove()

testValuesRemove

public void testValuesRemove()

testValuesRemoveMissing

public void testValuesRemoveMissing()

testValuesRemoveAll

public void testValuesRemoveAll()

testValuesRemoveAllNullFromEmpty

public void testValuesRemoveAllNullFromEmpty()

testValuesRetainAll

public void testValuesRetainAll()

testValuesRetainAllNullFromEmpty

public void testValuesRetainAllNullFromEmpty()

testValuesClear

public void testValuesClear()


Copyright © 2010-2012. All Rights Reserved.