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.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<? extends K,? extends V>>
Map
s.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
AbstractMapAssert(A actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
contains(MapEntry<? extends K,? extends V>... 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<? extends K,? extends V>... 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<? extends K,? extends V>... 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 |
containsValues(V... values)
Verifies that the actual map contains the given values.
|
S |
doesNotContain(MapEntry<? extends K,? extends V>... 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 |
doesNotContainKeys(K... keys)
Verifies that the actual map does not contain any of the given keys.
|
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<? extends K,? extends V>> customComparator)
Deprecated.
Custom element Comparator is not supported for MapEntry comparison.
|
as, as, asList, asString, 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, withThreadDumpOnError
public void isNullOrEmpty()
null
or empty.isNullOrEmpty
in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry<? extends K,? extends V>>
public void isEmpty()
public S isNotEmpty()
isNotEmpty
in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry<? extends K,? extends V>>
this
assertion object.public S hasSize(int expected)
public S hasSameSizeAs(Object other)
int[] oneTwoThree = {1, 2, 3};
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass
assertThat(elvesRings).hasSameSizeAs(oneTwoThree);
hasSameSizeAs
in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry<? extends K,? extends V>>
other
- the array to compare size with actual group.this
assertion object.public S hasSameSizeAs(Iterable<?> other)
Iterable
.
Example:
Iterable<String> abc = newArrayList("a", "b", "c");
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass
assertThat(elvesRings).hasSameSizeAs(abc);
hasSameSizeAs
in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry<? extends K,? extends V>>
other
- the Iterable
to compare size with actual group.this
assertion object.public S hasSameSizeAs(Map<?,?> other)
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)));
other
- the Map
to compare size with actual mapthis
assertion objectNullPointerException
- 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 sizepublic S contains(MapEntry<? extends K,? extends V>... entries)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));
entries
- the given entries.this
assertion object.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.public S containsEntry(K key, V value)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).containsEntry(oneRing, frodo).containsEntry(nenya, galadriel);
key
- the given key to check.value
- the given value to check.this
assertion object.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.public S doesNotContain(MapEntry<? extends K,? extends V>... entries)
Example :
Map ringBearers = ... // init omitted
assertThat(ringBearers).doesNotContain(entry(oneRing, aragorn));
entries
- the given entries.this
assertion object.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.public S doesNotContainEntry(K key, V value)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).doesNotContainEntry(oneRing, aragorn);
key
- key of the entry.value
- value of the entry.this
assertion object.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.public S containsKey(K key)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).containsKey(oneRing);
key
- the given keyAssertionError
- if the actual map is null
.AssertionError
- if the actual map does not contain the given key.public S containsKeys(K... keys)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).containsKeys(nenya, oneRing);
keys
- the given keysAssertionError
- 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.public S doesNotContainKey(K key)
Example :
Map ringBearers = ... // init with elves rings only
assertThat(ringBearers).doesNotContainKey(oneRing);
key
- the given keyAssertionError
- if the actual map is null
.AssertionError
- if the actual map contains the given key.public S doesNotContainKeys(K... keys)
Example :
Map ringBearers = ... // init with elves rings only
assertThat(ringBearers).doesNotContainKeys(oneRing, someManRing);
key
- the given keyAssertionError
- if the actual map is null
.AssertionError
- if the actual map contains the given key.public S containsOnlyKeys(K... keys)
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);
keys
- the given keys that should be in the actual map.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.public S containsValue(V value)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).containsValue(frodo);
value
- the value to look for.AssertionError
- if the actual map is null
.AssertionError
- if the actual map does not contain the given value.public S containsValues(V... values)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).containsValues(frodo, galadriel);
values
- the values to look for in the actual map.AssertionError
- if the actual map is null
.AssertionError
- if the actual map does not contain the given values.public S doesNotContainValue(V value)
Example :
Map ringBearers = ... // init with elves rings and the one ring
assertThat(ringBearers).doesNotContainValue(aragorn);
value
- the value that should not be in actual map.AssertionError
- if the actual map is null
.AssertionError
- if the actual map contains the given value.public S containsOnly(MapEntry<? extends K,? extends V>... entries)
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));
entries
- the entries that should be in the actual map.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.public S containsExactly(MapEntry<? extends K,? extends V>... entries)
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));
entries
- the given entries.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.@Deprecated public S usingElementComparator(Comparator<? super MapEntry<? extends K,? extends V>> customComparator)
usingElementComparator
in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry<? extends K,? extends V>>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.UnsupportedOperationException
- if this method is called.@Deprecated public S usingDefaultElementComparator()
usingDefaultElementComparator
in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,MapEntry<? extends K,? extends V>>
this
assertion object.UnsupportedOperationException
- if this method is called.Copyright © 2013-2015 AssertJ. All Rights Reserved.