org.assertj.core.api
Class AbstractMapAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>,K,V>

java.lang.Object
  extended by org.assertj.core.api.AbstractAssert<S,A>
      extended by org.assertj.core.api.AbstractMapAssert<S,A,K,V>
Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
A - the type of the "actual" value.
K - the type of keys in map.
V - the type of values in map.
All Implemented Interfaces:
Assert<S,A>, Descriptable<S>, EnumerableAssert<S,MapEntry>, ExtensionPoints<S,A>
Direct Known Subclasses:
MapAssert

public abstract class AbstractMapAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>,K,V>
extends AbstractAssert<S,A>
implements EnumerableAssert<S,MapEntry>

Base class for all implementations of assertions for Maps.

Author:
David DIDIER, Yvonne Wang, Alex Ruiz, Mikhail Mazursky, Nicolas François

Field Summary
 
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself
 
Constructor Summary
protected AbstractMapAssert(A actual, Class<?> selfType)
           
 
Method Summary
 S contains(MapEntry... entries)
          Verifies that the actual map contains the given entries, in any order.
 S containsEntry(K key, V value)
          Verifies that the actual map contains the given entry.
 S containsExactly(MapEntry... entries)
          Verifies that the actual map contains only the given entries and nothing else, in order.
This assertion should only be used with map that have a consistent iteration order (i.e.
 S containsKey(K key)
          Verifies that the actual map contains the given key.
 S containsKeys(K... keys)
          Verifies that the actual map contains the given keys.
 S containsOnly(MapEntry... entries)
          Verifies that the actual map contains only the given entries and nothing else, in any order.
 S containsOnlyKeys(K... keys)
          Verifies that the actual map contains only the given keys and nothing else, in any order.
 S containsValue(V value)
          Verifies that the actual map contains the given value.
 S doesNotContain(MapEntry... entries)
          Verifies that the actual map does not contain the given entries.
 S doesNotContainEntry(K key, V value)
          Verifies that the actual map does not contain the given entry.
 S doesNotContainKey(K key)
          Verifies that the actual map does not contain the given key.
 S doesNotContainValue(V value)
          Verifies that the actual map does not contain the given value.
 S hasSameSizeAs(Iterable<?> other)
          Verifies that the actual group has the same size as given Iterable.
 S hasSameSizeAs(Map<?,?> other)
          Verifies that the actual map has the same size as the given Map.
 S hasSameSizeAs(Object other)
          Verifies that the actual group has the same size as given array.
 S hasSize(int expected)
          Verifies that the number of values in the actual group is equal to the given one.
 void isEmpty()
          Verifies that the actual group of values is empty.
 S isNotEmpty()
          Verifies that the actual group of values is not empty.
 void isNullOrEmpty()
          Verifies that the actual group of values is null or empty.
 S usingDefaultElementComparator()
          Deprecated. Custom element Comparator is not supported for MapEntry comparison.
 S usingElementComparator(Comparator<? super MapEntry> customComparator)
          Deprecated. Custom element Comparator is not supported for MapEntry comparison.
 
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMapAssert

protected AbstractMapAssert(A actual,
                            Class<?> selfType)
Method Detail

isNullOrEmpty

public void isNullOrEmpty()
Verifies that the actual group of values is null or empty.

Specified by:
isNullOrEmpty in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>

isEmpty

public void isEmpty()
Verifies that the actual group of values is empty.

Specified by:
isEmpty in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>

isNotEmpty

public S isNotEmpty()
Verifies that the actual group of values is not empty.

Specified by:
isNotEmpty in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>
Returns:
this assertion object.

hasSize

public S hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.

Specified by:
hasSize in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>
Parameters:
expected - the expected number of values in the actual group.
Returns:
this assertion object.

hasSameSizeAs

public S hasSameSizeAs(Object other)
Verifies that the actual group has the same size as given array.

Parameter is declared as Object to accept both Object[] and primitive arrays (e.g. int[]).

Specified by:
hasSameSizeAs in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>
Parameters:
other - the array to compare size with actual group.
Returns:
this assertion object.

hasSameSizeAs

public S hasSameSizeAs(Iterable<?> other)
Verifies that the actual group has the same size as given Iterable.

Specified by:
hasSameSizeAs in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>
Parameters:
other - the Iterable to compare size with actual group.
Returns:
this assertion object.

hasSameSizeAs

public S hasSameSizeAs(Map<?,?> other)
Verifies that the actual map has the same size as the given Map.

Example :

 Map ringBearers = ... // init with elves rings and the one ring
 
 assertThat(ringBearers).hasSameSizeAs(mapOf(entry(oneRing, frodo),
                                             entry(narya, gandalf),
                                             entry(nenya, galadriel),
                                             entry(vilya, elrond)));
 

Parameters:
other - the Map to compare size with actual map
Returns:
this assertion object
Throws:
NullPointerException - if the other Map is null
AssertionError - if the actual map is null
AssertionError - if the actual map and the given Map don't have the same size

contains

public S contains(MapEntry... entries)
Verifies that the actual map contains the given entries, in any order.

Example :

 Map ringBearers = ... // init with elves rings and the one ring
 
 assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));
 

Parameters:
entries - the given entries.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
NullPointerException - if any of the entries in the given array is null.
AssertionError - if the actual map is null.
AssertionError - if the actual map does not contain the given entries.

containsEntry

public S containsEntry(K key,
                       V value)
Verifies that the actual map contains the given entry.

Example :

 Map ringBearers = ... // init with elves rings and the one ring
 
 assertThat(ringBearers).containsEntry(oneRing, frodo).containsEntry(nenya, galadriel);
 

Parameters:
key - the given key to check.
value - the given value to check.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
NullPointerException - if any of the entries in the given array is null.
AssertionError - if the actual map is null.
AssertionError - if the actual map does not contain the given entries.

doesNotContain

public S doesNotContain(MapEntry... entries)
Verifies that the actual map does not contain the given entries.

Example :

 Map ringBearers = ... // init omitted
 assertThat(ringBearers).doesNotContain(entry(oneRing, aragorn));
 

Parameters:
entries - the given entries.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual map is null.
AssertionError - if the actual map contains any of the given entries.

doesNotContainEntry

public S doesNotContainEntry(K key,
                             V value)
Verifies that the actual map does not contain the given entry.

Example :

 Map ringBearers = ... // init with elves rings and the one ring
 
 assertThat(ringBearers).doesNotContainEntry(oneRing, aragorn);
 

Parameters:
key - key of the entry.
value - value of the entry.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual map is null.
AssertionError - if the actual map contains any of the given entries.

containsKey

public S containsKey(K key)
Verifies that the actual map contains the given key.

Parameters:
key - the given key
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual map does not contain the given key.

containsKeys

public S containsKeys(K... keys)
Verifies that the actual map contains the given keys.

Parameters:
keys - the given keys
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual map does not contain the given key.
IllegalArgumentException - if the given argument is an empty array.

doesNotContainKey

public S doesNotContainKey(K key)
Verifies that the actual map does not contain the given key.

Parameters:
key - the given key
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual map contains the given key.

containsOnlyKeys

public S containsOnlyKeys(K... keys)
Verifies that the actual map contains only the given keys and nothing else, in any order.

Examples :

 Map ringBearers = ... // init with elves rings and the one ring
 
 // assertion will pass
 assertThat(ringBearers).containsOnlyKeys(oneRing, nenya, narya, vilya);
 
 // assertion will fail
 assertThat(ringBearers).containsOnlyKeys(oneRing, nenya);
 

Parameters:
keys - the given keys that should be in the actual map.
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual map does not contain the given keys, i.e. the actual map contains some or none of the given keys, or the actual map contains more entries than the given ones.
IllegalArgumentException - if the given argument is an empty array.

containsValue

public S containsValue(V value)
Verifies that the actual map contains the given value.
 Map ringBearers = ... // init with elves rings and the one ring
 
 assertThat(ringBearers).containsValue(frodo);
 

Parameters:
value - the value to look for.
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual map does not contain the given value.

doesNotContainValue

public S doesNotContainValue(V value)
Verifies that the actual map does not contain the given value.
 Map ringBearers = ... // init with elves rings and the one ring
 
 assertThat(ringBearers).doesNotContainValue(aragorn);
 

Parameters:
value - the value that should not be in actual map.
Throws:
AssertionError - if the actual map is null.
AssertionError - if the actual map contains the given value.

containsOnly

public S containsOnly(MapEntry... entries)
Verifies that the actual map contains only the given entries and nothing else, in any order.

Examples :

 Map ringBearers = ... // init with elves rings and the one ring
 
 // assertion will pass
 assertThat(ringBearers).containsOnly(entry(oneRing, frodo), entry(nenya, galadriel), entry(narya, gandalf), entry(vilya, elrond));
 
 // assertion will fail
 assertThat(ringBearers).containsOnly(entry(oneRing, frodo), entry(nenya, galadriel));
 

Parameters:
entries - the entries that should be in the actual map.
Throws:
AssertionError - if the actual map is null.
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual map does not contain the given entries, i.e. the actual map contains some or none of the given entries, or the actual map contains more entries than the given ones.

containsExactly

public S containsExactly(MapEntry... entries)
Verifies that the actual map contains only the given entries and nothing else, in order.
This assertion should only be used with map that have a consistent iteration order (i.e. don't use it with HashMap, prefer containsOnly(org.assertj.core.data.MapEntry...) in that case).

Example :

 Map<Ring, TolkienCharacter> ringBearers = newLinkedHashMap(entry(oneRing, frodo), entry(nenya, galadriel),
                                                            entry(narya, gandalf));
 
 // assertion will pass
 assertThat(ringBearers).containsExactly(entry(oneRing, frodo), entry(nenya, galadriel), entry(narya, gandalf));
 
 // assertion will fail as actual and expected orders differ.
 assertThat(ringBearers).containsExactly(entry(nenya, galadriel), entry(narya, gandalf), entry(oneRing, frodo));
 

Parameters:
entries - the given entries.
Throws:
NullPointerException - if the given entries array is null.
AssertionError - if the actual map is null.
IllegalArgumentException - if the given entries array is empty.
AssertionError - if the actual map does not contain the given entries with same order, i.e. the actual map contains some or none of the given entries, or the actual map contains more entries than the given ones or entries are the same but the order is not.

usingElementComparator

@Deprecated
public final S usingElementComparator(Comparator<? super MapEntry> customComparator)
Deprecated. Custom element Comparator is not supported for MapEntry comparison.

Do not use this method.

Specified by:
usingElementComparator in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>
Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.
Throws:
UnsupportedOperationException - if this method is called.

usingDefaultElementComparator

@Deprecated
public final S usingDefaultElementComparator()
Deprecated. Custom element Comparator is not supported for MapEntry comparison.

Do not use this method.

Specified by:
usingDefaultElementComparator in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry>
Returns:
this assertion object.
Throws:
UnsupportedOperationException - if this method is called.


Copyright © 2013–2015 AssertJ. All rights reserved.