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

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by com.google.common.collect.testing.AbstractTester<OneSizeTestContainerGenerator<C,E>>
              extended by com.google.common.collect.testing.AbstractContainerTester<Map<K,V>,Map.Entry<K,V>>
                  extended by com.google.common.collect.testing.AbstractMapTester<K,V>
Type Parameters:
K - the key type of the map to be tested.
V - the value type of the map to be tested.
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
MapClearTester, MapContainsKeyTester, MapContainsValueTester, MapCreationTester, MapEqualsTester, MapGetTester, MapHashCodeTester, MapIsEmptyTester, MapNavigationTester, MapPutAllTester, MapPutTester, MapRemoveTester, MapSizeTester

public abstract class AbstractMapTester<K,V>
extends AbstractContainerTester<Map<K,V>,Map.Entry<K,V>>

Base class for map testers.

This class is GWT compatible. TODO: see how much of this is actually needed once Map testers are written. (It was cloned from AbstractCollectionTester.)

Author:
George van den Driessche

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.common.collect.testing.AbstractContainerTester
AbstractContainerTester.ArrayWithDuplicate<E>
 
Field Summary
 
Fields inherited from class com.google.common.collect.testing.AbstractContainerTester
container, samples
 
Constructor Summary
AbstractMapTester()
           
 
Method Summary
protected  Collection<Map.Entry<K,V>> actualContents()
           
protected  Map.Entry<K,V>[] createArrayWithNullKey()
           
protected  Map.Entry<K,V>[] createArrayWithNullValue()
           
protected  MinimalCollection<Map.Entry<K,V>> createDisjointCollection()
           
protected  Map.Entry<K,V> entry(K key, V value)
           
protected  void expectContents(Collection<Map.Entry<K,V>> expected)
          Asserts that the collection under test contains exactly the given elements, respecting cardinality but not order.
protected  void expectMissing(Map.Entry<K,V>... entries)
           
protected  void expectMissingKeys(K... elements)
           
protected  void expectMissingValues(V... elements)
           
protected  void expectNullKeyMissingWhenNullKeysUnsupported(String message)
          Equivalent to expectMissingKeys (null) except that the call to contains(null) is permitted to throw a NullPointerException.
protected  void expectNullValueMissingWhenNullValuesUnsupported(String message)
          Equivalent to expectMissingValues (null) except that the call to contains(null) is permitted to throw a NullPointerException.
protected  void expectReplacement(Map.Entry<K,V> newEntry)
           
protected  V get(K key)
          Wrapper for Map.get(Object) that forces the caller to pass in a key of the same type as the map.
protected  K getKeyForNullValue()
           
protected  Map<K,V> getMap()
           
protected  int getNumEntries()
           
protected  Collection<Map.Entry<K,V>> getSampleEntries()
           
protected  Collection<Map.Entry<K,V>> getSampleEntries(int howMany)
           
protected  V getValueForNullKey()
           
protected  void initMapWithNullKey()
           
protected  void initMapWithNullValue()
           
protected  void resetMap()
           
protected  void resetMap(Map.Entry<K,V>[] entries)
           
 void setUp()
           
 
Methods inherited from class com.google.common.collect.testing.AbstractContainerTester
createArrayWithDuplicateElement, createSamplesArray, emptyCollection, expectAdded, expectAdded, expectAdded, expectContents, expectUnchanged, getNullLocation, getNumElements, getOrderedElements, getSampleElements, getSampleElements, resetContainer, resetContainer
 
Methods inherited from class com.google.common.collect.testing.AbstractTester
getName, getSubjectGenerator, getTestMethodName, init, init, tearDown
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, run, run, runBare, runTest, setName, 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
 

Constructor Detail

AbstractMapTester

public AbstractMapTester()
Method Detail

getMap

protected Map<K,V> getMap()

setUp

public void setUp()
           throws Exception
Overrides:
setUp in class AbstractContainerTester<Map<K,V>,Map.Entry<K,V>>
Throws:
Exception

actualContents

protected Collection<Map.Entry<K,V>> actualContents()
Specified by:
actualContents in class AbstractContainerTester<Map<K,V>,Map.Entry<K,V>>
Returns:
the contents of the container under test, for use by expectContents(E...) and its friends.

resetMap

protected void resetMap()
See Also:
AbstractContainerTester.resetContainer()

expectMissingKeys

protected void expectMissingKeys(K... elements)

expectMissingValues

protected void expectMissingValues(V... elements)

createArrayWithNullKey

protected Map.Entry<K,V>[] createArrayWithNullKey()
Returns:
an array of the proper size with null as the key of the middle element.

getValueForNullKey

protected V getValueForNullKey()

getKeyForNullValue

protected K getKeyForNullValue()

createArrayWithNullValue

protected Map.Entry<K,V>[] createArrayWithNullValue()
Returns:
an array of the proper size with null as the value of the middle element.

initMapWithNullKey

protected void initMapWithNullKey()

initMapWithNullValue

protected void initMapWithNullValue()

expectNullKeyMissingWhenNullKeysUnsupported

protected void expectNullKeyMissingWhenNullKeysUnsupported(String message)
Equivalent to expectMissingKeys (null) except that the call to contains(null) is permitted to throw a NullPointerException.

Parameters:
message - message to use upon assertion failure

expectNullValueMissingWhenNullValuesUnsupported

protected void expectNullValueMissingWhenNullValuesUnsupported(String message)
Equivalent to expectMissingValues (null) except that the call to contains(null) is permitted to throw a NullPointerException.

Parameters:
message - message to use upon assertion failure

createDisjointCollection

protected MinimalCollection<Map.Entry<K,V>> createDisjointCollection()
Overrides:
createDisjointCollection in class AbstractContainerTester<Map<K,V>,Map.Entry<K,V>>

getNumEntries

protected int getNumEntries()

getSampleEntries

protected Collection<Map.Entry<K,V>> getSampleEntries(int howMany)

getSampleEntries

protected Collection<Map.Entry<K,V>> getSampleEntries()

expectMissing

protected void expectMissing(Map.Entry<K,V>... entries)
Overrides:
expectMissing in class AbstractContainerTester<Map<K,V>,Map.Entry<K,V>>

entry

protected Map.Entry<K,V> entry(K key,
                               V value)

expectContents

protected void expectContents(Collection<Map.Entry<K,V>> expected)
Description copied from class: AbstractContainerTester
Asserts that the collection under test contains exactly the given elements, respecting cardinality but not order. Subclasses may override this method to provide stronger assertions, e.g., to check ordering in lists, but realize that unless a test extends AbstractListTester, a call to expectContents() invokes this version.

Overrides:
expectContents in class AbstractContainerTester<Map<K,V>,Map.Entry<K,V>>
Parameters:
expected - expected value of AbstractContainerTester.container

expectReplacement

protected final void expectReplacement(Map.Entry<K,V> newEntry)

get

protected V get(K key)
Wrapper for Map.get(Object) that forces the caller to pass in a key of the same type as the map. Besides being slightly shorter than code that uses getMap(), it also ensures that callers don't pass an Map.Entry by mistake.


resetMap

protected void resetMap(Map.Entry<K,V>[] entries)


Copyright © 2010-2011. All Rights Reserved.