java.lang.Object
junit.framework.Assert
junit.framework.TestCase
com.google.common.collect.testing.MapInterfaceTest<K,V>
- Type Parameters:
K
- the type of keys used by the maps under testV
- the type of mapped values used the maps under test
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
SortedMapInterfaceTest
@GwtCompatible
@NullMarked
public abstract class MapInterfaceTest<K extends @Nullable Object,V extends @Nullable Object>
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.- Author:
- George van den Driessche
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final boolean
protected final boolean
protected final boolean
protected final boolean
protected final boolean
protected final boolean
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
MapInterfaceTest
(boolean allowsNullKeys, boolean allowsNullValues, boolean supportsPut, boolean supportsRemove, boolean supportsClear) Constructor that assignssupportsIteratorRemove
the same value assupportsRemove
.protected
MapInterfaceTest
(boolean allowsNullKeys, boolean allowsNullValues, boolean supportsPut, boolean supportsRemove, boolean supportsClear, boolean supportsIteratorRemove) Constructor with an explicitsupportsIteratorRemove
parameter. -
Method Summary
Modifier and TypeMethodDescriptionprotected final 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
Creates a new key that is not expected to be found inmakePopulatedMap()
.protected abstract V
Creates a new value that is not expected to be found inmakePopulatedMap()
.Used by tests that require a map, but don't care whether it's populated or not.Creates a new, empty instance of the class under test.Creates a new, non-empty instance of the class under test.protected final boolean
supportsValuesHashCode
(Map<K, V> map) void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
testGet()
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
void
testSize()
void
void
void
void
void
void
void
void
void
Methods inherited from class junit.framework.TestCase
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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
-
Field Details
-
supportsPut
-
supportsRemove
-
supportsClear
-
allowsNullKeys
-
allowsNullValues
-
supportsIteratorRemove
-
-
Constructor Details
-
MapInterfaceTest
protected MapInterfaceTest(boolean allowsNullKeys, boolean allowsNullValues, boolean supportsPut, boolean supportsRemove, boolean supportsClear) Constructor that assignssupportsIteratorRemove
the same value assupportsRemove
. -
MapInterfaceTest
protected MapInterfaceTest(boolean allowsNullKeys, boolean allowsNullValues, boolean supportsPut, boolean supportsRemove, boolean supportsClear, boolean supportsIteratorRemove) Constructor with an explicitsupportsIteratorRemove
parameter.
-
-
Method Details
-
makeEmptyMap
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
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
Creates a new key that is not expected to be found inmakePopulatedMap()
.- Returns:
- a key.
- Throws:
UnsupportedOperationException
- if it's not possible to make a key that will not be found in the map.
-
getValueNotInPopulatedMap
Creates a new value that is not expected to be found inmakePopulatedMap()
.- Returns:
- a value.
- Throws:
UnsupportedOperationException
- if it's not possible to make a value that will not be found in the map.
-
makeEitherMap
Used by tests that require a map, but don't care whether it's populated or not.- Returns:
- a new map instance.
-
supportsValuesHashCode
-
assertInvariants
Checks all the properties that should always hold of a map. Also callsassertMoreInvariants(java.util.Map<K, V>)
to check invariants that are peculiar to specific implementations.- Parameters:
map
- the map to check.- See Also:
-
assertMoreInvariants
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
-
testContainsKey
-
testContainsValue
-
testEntrySet
-
testEntrySetForEmptyMap
-
testEntrySetContainsEntryIncompatibleKey
-
testEntrySetContainsEntryNullKeyPresent
-
testEntrySetContainsEntryNullKeyMissing
-
testEntrySetIteratorRemove
-
testEntrySetRemove
-
testEntrySetRemoveMissingKey
-
testEntrySetRemoveDifferentValue
-
testEntrySetRemoveNullKeyPresent
-
testEntrySetRemoveNullKeyMissing
-
testEntrySetRemoveAll
-
testEntrySetRemoveAllNullFromEmpty
-
testEntrySetRetainAll
-
testEntrySetRetainAllNullFromEmpty
-
testEntrySetClear
-
testEntrySetAddAndAddAll
-
testEntrySetSetValue
-
testEntrySetSetValueSameValue
-
testEqualsForEqualMap
-
testEqualsForLargerMap
-
testEqualsForSmallerMap
-
testEqualsForEmptyMap
-
testGet
-
testGetForEmptyMap
-
testGetNull
-
testHashCode
-
testHashCodeForEmptyMap
-
testPutNewKey
-
testPutExistingKey
-
testPutNullKey
-
testPutNullValue
-
testPutNullValueForExistingKey
-
testPutAllNewKey
-
testPutAllExistingKey
-
testRemove
-
testRemoveMissingKey
-
testSize
-
testKeySetRemove
-
testKeySetRemoveAll
-
testKeySetRetainAll
-
testKeySetClear
-
testKeySetRemoveAllNullFromEmpty
-
testKeySetRetainAllNullFromEmpty
-
testValues
-
testValuesIteratorRemove
-
testValuesRemove
-
testValuesRemoveMissing
-
testValuesRemoveAll
-
testValuesRemoveAllNullFromEmpty
-
testValuesRetainAll
-
testValuesRetainAllNullFromEmpty
-
testValuesClear
-