Class AbstractMapAssert<SELF extends AbstractMapAssert<SELF,ACTUAL,K,V>,ACTUAL extends Map<K,V>,K,V>
- Type Parameters:
SELF
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.ACTUAL
- the type of the "actual" value.K
- the type of keys in map.V
- the type of values in map.
- All Implemented Interfaces:
Assert<SELF,
,ACTUAL> Descriptable<SELF>
,EnumerableAssert<SELF,
,Map.Entry<? extends K, ? extends V>> ExtensionPoints<SELF,
ACTUAL>
- Direct Known Subclasses:
MapAssert
,SoftAssertionMapAssert
Map
s.-
Field Summary
FieldsFields inherited from class org.assertj.core.api.AbstractAssert
actual, conditions, info, myself, objects
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the description of the assertion that is going to be called after.as
(Description description) Sets the description of the assertion that is going to be called after.Verifies that the actual map contains the given entries, in any order.containsAllEntriesOf
(Map<? extends K, ? extends V> other) Verifies that the actual map contains all entries of the given map, in any order.containsAnyOf
(Map.Entry<? extends K, ? extends V>... entries) Verifies that the actual map contains at least one of the given entries.containsEntry
(K key, V value) Verifies that the actual map contains the given entry.containsExactly
(Map.Entry<? 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 maps that have a consistent iteration order (i.e.containsKey
(K key) Verifies that the actual map contains the given key.containsKeys
(K... keys) Verifies that the actual map contains the given keys.containsOnly
(Map.Entry<? extends K, ? extends V>... entries) Verifies that the actual map contains only the given entries and nothing else, in any order.containsOnlyKeys
(K... keys) Verifies that the actual map contains only the given keys and nothing else, in any order.containsValue
(V value) Verifies that the actual map contains the given value.containsValues
(V... values) Verifies that the actual map contains the given values.describedAs
(String description, Object... args) Sets the description of the assertion that is going to be called after.describedAs
(Description description) Sets the description of the assertion that is going to be called after.doesNotContain
(Map.Entry<? extends K, ? extends V>... entries) Verifies that the actual map does not contain the given entries.doesNotContainEntry
(K key, V value) Verifies that the actual map does not contain the given entry.doesNotContainKey
(K key) Verifies that the actual map does not contain the given key.doesNotContainKeys
(K... keys) Verifies that the actual map does not contain any of the given keys.doesNotContainValue
(V value) Verifies that the actual map does not contain the given value.doesNotHave
(Condition<? super ACTUAL> condition) Verifies that the actual value does not satisfy the given condition.doesNotHaveSameClassAs
(Object other) Verifies that the actual value does not have the same class as the given object.extracting
(String... keys) Extract the values of given keys from the map under test into an array, this new array becoming the object under test.Verifies that the actual value satisfies the given condition.hasEntrySatisfying
(K key, Consumer<? super V> valueRequirements) Verifies that the actual map contains the value for givenkey
that satisfy givenvalueRequirements
.hasEntrySatisfying
(K key, Condition<? super V> valueCondition) Verifies that the actual map contains a value for the givenkey
that satisfies the givenvalueCondition
.hasEntrySatisfying
(Condition<? super Map.Entry<K, V>> entryCondition) Verifies that the actual map contains an entry satisfying the givenentryCondition
.hasEntrySatisfying
(Condition<? super K> keyCondition, Condition<? super V> valueCondition) Verifies that the actual map contains an entry with a key satisfying the givenkeyCondition
and a value satisfying the givenvalueCondition
.hasKeySatisfying
(Condition<? super K> keyCondition) Verifies that the actual map contains an entry with a key satisfying the givenkeyCondition
.hasSameClassAs
(Object other) Verifies that the actual value has the same class as the given object.hasSameSizeAs
(Iterable<?> other) Verifies that the actual map has the same size as the givenIterable
.hasSameSizeAs
(Object other) Verifies that the actual map has the same size as the given array.hasSameSizeAs
(Map<?, ?> other) Verifies that the actual map has the same size as the givenMap
.hasSize
(int expected) Verifies that the number of values in theMap
is equal to the given one.hasToString
(String expectedToString) Verifies that actualactual.toString()
is equal to the givenString
.hasValueSatisfying
(Condition<? super V> valueCondition) Verifies that the actual map contains an entry with a value satisfying the givenvalueCondition
.Verifies that the actual value satisfies the given condition.void
isEmpty()
Verifies that theMap
is empty.Verifies that the actual value is equal to the given one.isExactlyInstanceOf
(Class<?> type) Verifies that the actual value is exactly an instance of the given type.Verifies that the actual value is present in the given values.Verifies that the actual value is present in the given array of values.isInstanceOf
(Class<?> type) Verifies that the actual value is an instance of the given type.isInstanceOfAny
(Class<?>... types) Verifies that the actual value is an instance of any of the given types.Verifies that the actual value does not satisfy the given condition.Verifies that theMap
is not empty.isNotEqualTo
(Object other) Verifies that the actual value is not equal to the given one.isNotExactlyInstanceOf
(Class<?> type) Verifies that the actual value is not exactly an instance of given type.Verifies that the actual value is not present in the given values.Verifies that the actual value is not present in the given array of values.isNotInstanceOf
(Class<?> type) Verifies that the actual value is not an instance of the given type.isNotInstanceOfAny
(Class<?>... types) Verifies that the actual value is not an instance of any of the given types.Verifies that the actual value is notnull
.isNotOfAnyClassIn
(Class<?>... types) Verifies that the actual value type is not in given types.isNotSameAs
(Object other) Verifies that the actual value is not the same as the given one, ie using == comparison.void
Verifies that theMap
isnull
or empty.isOfAnyClassIn
(Class<?>... types) Verifies that the actual value type is in given types.Verifies that the actual value is the same as the given one, ie using == comparison.overridingErrorMessage
(String newErrorMessage, Object... args) Overrides AssertJ default error message by the given one.size()
Returns anAssert
object that allows performing assertions on the size of theMap
under test.usingComparator
(Comparator<? super ACTUAL> customComparator) Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Revert to standard comparison for incoming assertion checks.Deprecated.Custom element Comparator is not supported for MapEntry comparison.usingElementComparator
(Comparator<? super Map.Entry<? extends K, ? extends V>> customComparator) Deprecated.Custom element Comparator is not supported for MapEntry comparison.withFailMessage
(String newErrorMessage, Object... args) Alternative method forAbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...)
In case of an assertion error, a thread dump will be printed toSystem.err
.Methods inherited from class org.assertj.core.api.AbstractObjectAssert
defaultTypeComparators, extracting, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, returns, usingComparatorForFields, usingComparatorForType
Methods inherited from class org.assertj.core.api.AbstractAssert
asList, asString, descriptionText, equals, failWithMessage, getWritableAssertionInfo, hashCode, inBinary, inHexadecimal, isInstanceOfSatisfying, isNull, matches, matches, satisfies, setCustomRepresentation, throwAssertionError, withRepresentation
-
Field Details
-
maps
Maps maps
-
-
Constructor Details
-
AbstractMapAssert
-
-
Method Details
-
isNullOrEmpty
public void isNullOrEmpty()Verifies that theMap
isnull
or empty.Example:
// assertions will pass Map<Integer, String> map = null; assertThat(map).isNullOrEmpty(); assertThat(new HashMap()).isNullOrEmpty(); // assertion will fail Map<String, String> keyToValue = new HashMap(); keyToValue.put("key", "value"); assertThat(keyToValue).isNullOrEmpty()
- Specified by:
isNullOrEmpty
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Throws:
AssertionError
- if theMap
is notnull
or not empty.
-
isEmpty
public void isEmpty()Verifies that theMap
is empty.Example:
// assertion will pass assertThat(new HashMap()).isEmpty(); // assertion will fail Map<String, String> map = new HashMap(); map.put("key", "value"); assertThat(map).isEmpty();
- Specified by:
isEmpty
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Throws:
AssertionError
- if theMap
of values is not empty.
-
isNotEmpty
Verifies that theMap
is not empty.Example:
Map<String, String> map = new HashMap(); map.put("key", "value"); // assertion will pass assertThat(map).isNotEmpty(); // assertion will fail assertThat(new HashMap()).isNotEmpty();
- Specified by:
isNotEmpty
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Returns:
this
assertion object.- Throws:
AssertionError
- if theMap
is empty.
-
hasSize
Verifies that the number of values in theMap
is equal to the given one.Example:
Map<String, String> map = new HashMap(); map.put("key", "value"); // assertion will pass assertThat(map).hasSize(1); // assertions will fail assertThat(map).hasSize(0); assertThat(map).hasSize(2);
- Specified by:
hasSize
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
expected
- the expected number of values in theMap
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the number of values of theMap
is not equal to the given one.
-
hasSameSizeAs
Verifies that the actual map has the same size as the given array.Parameter is declared as Object to accept both Object[] and primitive arrays (e.g. int[]).
Example:
int[] oneTwoThree = {1, 2, 3}; Map<Ring, TolkienCharacter> elvesRingBearers = new HashMap<>(); elvesRingBearers.put(nenya, galadriel); elvesRingBearers.put(narya, gandalf); elvesRingBearers.put(vilya, elrond); // assertion will pass assertThat(elvesRingBearers).hasSameSizeAs(oneTwoThree); // assertions will fail assertThat(elvesRingBearers).hasSameSizeAs(new int[] {1}); assertThat(keyToValue).hasSameSizeAs(new char[] {'a', 'b', 'c', 'd'});
- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
other
- the array to compare size with actual group.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual group isnull
.AssertionError
- if the array parameter isnull
or is not a true array.AssertionError
- if actual group and given array don't have the same size.
-
hasSameSizeAs
Verifies that the actual map has the same size as the givenIterable
.Example :
Map<Ring, TolkienCharacter> elvesRingBearers = new HashMap<>(); elvesRingBearers.put(nenya, galadriel); elvesRingBearers.put(narya, gandalf); elvesRingBearers.put(vilya, elrond); // assertion will pass assertThat(elvesRingBearers).hasSameSizeAs(Array.asList(vilya, nenya, narya)); // assertions will fail assertThat(elvesRingBearers).hasSameSizeAs(Array.asList(1)); assertThat(keyToValue).hasSameSizeAs(Array.asList('a', 'b', 'c', 'd'));
- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the otherIterable
isnull
.AssertionError
- if the actual map and the givenIterable
don't have the same size
-
hasSameSizeAs
Verifies that the actual map has the same size as the givenMap
.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertion will pass assertThat(ringBearers).hasSameSizeAs(mapOf(entry(oneRing, frodo), entry(narya, gandalf), entry(nenya, galadriel), entry(vilya, elrond))); // assertions will fail assertThat(elvesRingBearers).hasSameSizeAs(new HashMap()); Map<String, String> keyToValue = new HashMap(); keyToValue.put("key", "value"); assertThat(keyToValue).hasSameSizeAs(keyToValue);
- Parameters:
other
- theMap
to compare size with actual map- Returns:
this
assertion object- Throws:
NullPointerException
- if the otherMap
isnull
AssertionError
- if the actual map isnull
AssertionError
- if the actual map and the givenMap
don't have the same size
-
contains
Verifies that the actual map contains the given entries, in any order.This assertion succeeds if both actual map and given entries are empty.
Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertions will pass assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel)); assertThat(emptyMap).contains(); // assertions will fail assertThat(ringBearers).contains(entry(oneRing, sauron)); assertThat(ringBearers).contains(entry(oneRing, sauron), entry(oneRing, aragorn)); assertThat(ringBearers).contains(entry(narya, gandalf), entry(oneRing, sauron));
- Parameters:
entries
- the given entries.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.NullPointerException
- if any of the entries in the given array isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given entries.
-
containsAnyOf
Verifies that the actual map contains at least one of the given entries.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertions will pass assertThat(ringBearers).containsAnyOf(entry(oneRing, frodo), entry(oneRing, sauron)); assertThat(emptyMap).containsAnyOf(); // assertion will fail assertThat(ringBearers).containsAnyOf(entry(oneRing, gandalf), entry(oneRing, aragorn));
- Parameters:
entries
- the given entries.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.NullPointerException
- if any of the entries in the given array isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain any of the given entries.- Since:
- 3.6.0
-
containsAllEntriesOf
Verifies that the actual map contains all entries of the given map, in any order.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); Map<Ring, TolkienCharacter> elvesRingBearers = new HashMap<>(); elvesRingBearers.put(nenya, galadriel); elvesRingBearers.put(narya, gandalf); elvesRingBearers.put(vilya, elrond); // assertion will succeed assertThat(ringBearers).containsAllEntriesOf(elvesRingBearers); // assertion will fail assertThat(elvesRingBearers).containsAllEntriesOf(ringBearers);
- Parameters:
other
- the map with the given entries.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.NullPointerException
- if any of the entries in the given map isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given entries.
-
containsEntry
Verifies that the actual map contains the given entry.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertions will pass assertThat(ringBearers).containsEntry(oneRing, frodo).containsEntry(nenya, galadriel); // assertion will fail assertThat(ringBearers).containsEntry(oneRing, sauron);
- Parameters:
key
- the given key to check.value
- the given value to check.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.NullPointerException
- if any of the entries in the given array isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given entries.
-
hasEntrySatisfying
Verifies that the actual map contains a value for the givenkey
that satisfies the givenvalueCondition
.Example:
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); Condition<TolkienCharacterinvalid input: '>' elfBearer = new Condition<>("an elf bearer") { public boolean matches(TolkienCharacter character) { return character.getRace() == ELF; } }; // this assertion will pass assertThat(ringBearers).hasEntrySatisfying(nenya, elfBearer); // this assertion will fail assertThat(ringBearers).hasEntrySatisfying(oneRing, elfBearer);
- Parameters:
key
- he given key to check.valueCondition
- the given condition for check value.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given values isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map not contains the givenkey
.AssertionError
- if the actual map contains the given key, but value not match the givenvalueCondition
.- Since:
- 2.6.0 / 3.6.0
-
hasEntrySatisfying
Verifies that the actual map contains the value for givenkey
that satisfy givenvalueRequirements
.Example:
Map<Ring, TolkienCharacter> ringBearers = new HashMapinvalid input: '<'>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // this assertion will pass assertThat(ringBearers).hasEntrySatisfying(nenya, character -> { assertThat(character.getName()).contains("driel"); assertThat(character.getRace()).isEqualTo(ELF); }); // this assertion will fail assertThat(ringBearers).hasEntrySatisfying(oneRing, character -> { assertThat(character.getRace()).isEqualTo(ELF); });
- Parameters:
key
- he given key to check.valueRequirements
- the given requirements for check value.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given values isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map not contains the givenkey
.AssertionError
- if the actual map contains the given key, but value not pass the givenvalueRequirements
.- Since:
- 3.6.0
-
hasEntrySatisfying
Verifies that the actual map contains an entry satisfying the givenentryCondition
.Example:
Map<TolkienCharacter, Ring> ringBearers = new HashMap<>(); ringBearers.put(galadriel, nenya); ringBearers.put(gandalf, narya); ringBearers.put(elrond, vilya); ringBearers.put(frodo, oneRing); Condition<Map.Entry<TolkienCharacter, Ring>> oneRingManBearer = new Condition<Map.Entry<TolkienCharacter, Ring>>("One ring man bearer") { public boolean matches(Map.Entry<TolkienCharacter, Ring> entry) { return entry.getKey().getRace() == MAN invalid input: '&'invalid input: '&' entry.getValue() == oneRing; } }; // assertion will fail assertThat(ringBearers).hasEntrySatisfying(oneRingManBearer); ringBearers.put(isildur, oneRing); // now assertion will pass assertThat(ringBearers).hasEntrySatisfying(oneRingManBearer);
- Parameters:
entryCondition
- the condition for searching entry.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if there is no entry matching givenentryCondition
.- Since:
- 2.7.0 / 3.7.0
-
hasEntrySatisfying
public SELF hasEntrySatisfying(Condition<? super K> keyCondition, Condition<? super V> valueCondition) Verifies that the actual map contains an entry with a key satisfying the givenkeyCondition
and a value satisfying the givenvalueCondition
.Example:
Map<TolkienCharacter, Ring> ringBearers = new HashMap<>(); ringBearers.put(galadriel, nenya); ringBearers.put(gandalf, narya); ringBearers.put(elrond, vilya); ringBearers.put(frodo, oneRing); Condition<TolkienCharacter> isMan = new Condition<TolkienCharacter>("is man") { public boolean matches(TolkienCharacter tolkienCharacter) { return tolkienCharacter.getRace() == MAN; } }; Condition<Ring> oneRingBearer = new Condition<Ring>("One ring bearer") { public boolean matches(Ring ring) { return ring == oneRing; } }; // assertion will fail assertThat(ringBearers).hasEntrySatisfying(isMan, oneRingBearer); ringBearers.put(isildur, oneRing); // now assertion will pass assertThat(ringBearers).hasEntrySatisfying(isMan, oneRingBearer);
- Parameters:
keyCondition
- the condition to be matched by the entry's key.valueCondition
- the condition to be matched by the entry's value.- Returns:
this
assertion object.- Throws:
NullPointerException
- if any of the given conditions isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if there is no entry with a key matchingkeyCondition
and a value matchingvalueCondition
.- Since:
- 2.7.0 / 3.7.0
-
hasKeySatisfying
Verifies that the actual map contains an entry with a key satisfying the givenkeyCondition
.Example:
Map<TolkienCharacter, Ring> ringBearers = new HashMap<>(); ringBearers.put(galadriel, nenya); ringBearers.put(gandalf, narya); ringBearers.put(elrond, vilya); ringBearers.put(frodo, oneRing); Condition<TolkienCharacter> isElf = new Condition<TolkienCharacter>("is elf") { public boolean matches(TolkienCharacter tolkienCharacter) { return tolkienCharacter.getRace() == ELF; } }; Condition<TolkienCharacter> isOrc = new Condition<TolkienCharacter>("is orc") { public boolean matches(TolkienCharacter tolkienCharacter) { return tolkienCharacter.getRace() == ORC; } }; // assertion will pass assertThat(ringBearers).hasKeySatisfying(isElf); // assertion will fail assertThat(ringBearers).hasKeySatisfying(isOrc);
- Parameters:
keyCondition
- the condition to be matched by the entry's key.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if there is no key matching the givenkeyCondition
.- Since:
- 2.7.0 / 3.7.0
-
hasValueSatisfying
Verifies that the actual map contains an entry with a value satisfying the givenvalueCondition
.Example:
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); Condition<TolkienCharacter> isElf = new Condition<TolkienCharacter>("is elf") { public boolean matches(TolkienCharacter tolkienCharacter) { return tolkienCharacter.getRace() == ELF; } }; Condition<TolkienCharacter> isOrc = new Condition<TolkienCharacter>("is orc") { public boolean matches(TolkienCharacter tolkienCharacter) { return tolkienCharacter.getRace() == ORC; } }; // assertion will pass assertThat(ringBearers).hasValueSatisfying(isElf); // assertion will fail assertThat(ringBearers).hasValueSatisfying(isOrc);
- Parameters:
valueCondition
- the condition to be matched by the entry's value.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actual map isnull
.AssertionError
- if there is no value matching the givenvalueCondition
.- Since:
- 2.7.0 / 3.7.0
-
doesNotContain
Verifies that the actual map does not contain the given entries.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertion will pass assertThat(ringBearers).doesNotContain(entry(oneRing, aragorn), entry(oneRing, sauron)); // assertions will fail assertThat(ringBearers).doesNotContain(entry(oneRing, frodo)); assertThat(ringBearers).doesNotContain(entry(oneRing, frodo), entry(oneRing, aragorn));
- Parameters:
entries
- the given entries.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains any of the given entries.
-
doesNotContainEntry
Verifies that the actual map does not contain the given entry.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertion will pass assertThat(ringBearers).doesNotContainEntry(oneRing, aragorn); // assertion will fail assertThat(ringBearers).doesNotContain(oneRing, frodo);
- Parameters:
key
- key of the entry.value
- value of the entry.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains any of the given entries.
-
containsKey
Verifies that the actual map contains the given key.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); // assertion will pass assertThat(ringBearers).containsKey(vilya); // assertion will fail assertThat(ringBearers).containsKey(oneRing);
- Parameters:
key
- the given key- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given key.
-
containsKeys
Verifies that the actual map contains the given keys.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(oneRing, frodo); // assertions will pass assertThat(ringBearers).containsKeys(nenya, oneRing); // assertions will fail assertThat(ringBearers).containsKeys(vilya); assertThat(ringBearers).containsKeys(vilya, oneRing);
- Parameters:
keys
- the given keys- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given key.IllegalArgumentException
- if the given argument is an empty array.
-
doesNotContainKey
Verifies that the actual map does not contain the given key.Example :
Map<Ring, TolkienCharacter> elvesRingBearers = new HashMap<>(); elvesRingBearers.put(nenya, galadriel); elvesRingBearers.put(narya, gandalf); elvesRingBearers.put(vilya, elrond); // assertion will pass assertThat(elvesRingBearers).doesNotContainKey(oneRing); // assertion will fail assertThat(elvesRingBearers).doesNotContainKey(vilya);
- Parameters:
key
- the given key- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains the given key.
-
doesNotContainKeys
Verifies that the actual map does not contain any of the given keys.Example :
Map<Ring, TolkienCharacter> elvesRingBearers = new HashMap<>(); elvesRingBearers.put(nenya, galadriel); elvesRingBearers.put(narya, gandalf); elvesRingBearers.put(vilya, elrond); // assertion will pass assertThat(elvesRingBearers).doesNotContainKeys(oneRing, someManRing); // assertions will fail assertThat(elvesRingBearers).doesNotContainKeys(vilya, nenya); assertThat(elvesRingBearers).doesNotContainKeys(vilya, oneRing);
- Parameters:
keys
- the given keys- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains the given key.
-
containsOnlyKeys
Verifies that the actual map contains only the given keys and nothing else, in any order.Examples :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // 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 isnull
.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
Verifies that the actual map contains the given value.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertion will pass assertThat(ringBearers).containsValue(frodo); // assertion will fail assertThat(ringBearers).containsValue(sauron);
- Parameters:
value
- the value to look for.- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given value.
-
containsValues
Verifies that the actual map contains the given values.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertion will pass assertThat(ringBearers).containsValues(frodo, galadriel); // assertions will fail assertThat(ringBearers).containsValues(sauron, aragorn); assertThat(ringBearers).containsValues(sauron, frodo);
- Parameters:
values
- the values to look for in the actual map.- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map does not contain the given values.
-
doesNotContainValue
Verifies that the actual map does not contain the given value.Example :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // assertion will pass assertThat(ringBearers).doesNotContainValue(aragorn); // assertion will fail assertThat(ringBearers).doesNotContainValue(frodo);
- Parameters:
value
- the value that should not be in actual map.- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actual map contains the given value.
-
containsOnly
Verifies that the actual map contains only the given entries and nothing else, in any order.Examples :
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>(); ringBearers.put(nenya, galadriel); ringBearers.put(narya, gandalf); ringBearers.put(vilya, elrond); ringBearers.put(oneRing, frodo); // 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 isnull
.NullPointerException
- if the given argument isnull
.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
Verifies that the actual map contains only the given entries and nothing else, in order.
This assertion should only be used with maps that have a consistent iteration order (i.e. don't use it withHashMap
, prefercontainsOnly(java.util.Map.Entry...)
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 order 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 isnull
.AssertionError
- if the actual map isnull
.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 SELF usingElementComparator(Comparator<? super Map.Entry<? extends K, ? extends V>> customComparator) Deprecated.Custom element Comparator is not supported for MapEntry comparison.Do not use this method.- Specified by:
usingElementComparator
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.- Throws:
UnsupportedOperationException
- if this method is called.
-
usingDefaultElementComparator
Deprecated.Custom element Comparator is not supported for MapEntry comparison.Do not use this method.- Specified by:
usingDefaultElementComparator
in interfaceEnumerableAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Returns:
this
assertion object.- Throws:
UnsupportedOperationException
- if this method is called.
-
as
Description copied from class:AbstractAssert
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
The description follows
String.format(String, Object...)
syntax.Example :
try { // set a bad age to Mr Frodo which is really 33 years old. frodo.setAge(50); // specify a test description (call as() before the assertion !), it supports String format syntax. assertThat(frodo.getAge()).as("check %s's age", frodo.getName()).isEqualTo(33); } catch (AssertionError e) { assertThat(e).hasMessage("[check Frodo's age] expected:<[33]> but was:<[50]>"); }
- Specified by:
as
in interfaceDescriptable<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>> - Overrides:
as
in classAbstractObjectAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
description
- the new description to set.args
- optional parameter if description is a format String.- Returns:
this
object.- See Also:
-
as
Description copied from class:AbstractAssert
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
as
in interfaceDescriptable<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>> - Overrides:
as
in classAbstractObjectAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
description
- the new description to set.- Returns:
this
object.- See Also:
-
describedAs
Description copied from class:AbstractAssert
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
describedAs
in interfaceDescriptable<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>> - Overrides:
describedAs
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
description
- the new description to set.- Returns:
this
object.
-
describedAs
Description copied from class:AbstractAssert
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Alias for
since "as" is a keyword in Groovy.Descriptable.as(String, Object...)
- Specified by:
describedAs
in interfaceDescriptable<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>> - Overrides:
describedAs
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
description
- the new description to set.- Returns:
this
object.
-
doesNotHave
Description copied from class:AbstractAssert
Verifies that the actual value does not satisfy the given condition. This method is an alias for
.ExtensionPoints.isNot(Condition)
- Specified by:
doesNotHave
in interfaceExtensionPoints<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
doesNotHave
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
doesNotHaveSameClassAs
Description copied from class:AbstractAssert
Verifies that the actual value does not have the same class as the given object.Example:
// assertions will pass assertThat(1).doesNotHaveSameClassAs("abc"); assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new LinkedList<String>()); // assertions will fail assertThat(1).doesNotHaveSameClassAs(2); assertThat("abc").doesNotHaveSameClassAs("123"); assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new ArrayList<Integer>());
- Specified by:
doesNotHaveSameClassAs
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
doesNotHaveSameClassAs
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
other
- the object to check type against.- Returns:
- this assertion object.
-
has
Description copied from class:AbstractAssert
Verifies that the actual value satisfies the given condition. This method is an alias for
.ExtensionPoints.is(Condition)
- Specified by:
has
in interfaceExtensionPoints<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
has
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
hasSameClassAs
Description copied from class:AbstractAssert
Verifies that the actual value has the same class as the given object.Example:
// assertions will pass assertThat(1).hasSameClassAs(2); assertThat("abc").hasSameClassAs("123"); assertThat(new ArrayList<String>()).hasSameClassAs(new ArrayList<Integer>()); // assertions will fail assertThat(1).hasSameClassAs("abc"); assertThat(new ArrayList<String>()).hasSameClassAs(new LinkedList<String>());
- Specified by:
hasSameClassAs
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
hasSameClassAs
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
other
- the object to check type against.- Returns:
- this assertion object.
-
hasToString
Description copied from class:AbstractAssert
Verifies that actualactual.toString()
is equal to the givenString
.Example :
CartoonCaracter homer = new CartoonCaracter("Homer"); // Instead of writing ... assertThat(homer.toString()).isEqualTo("Homer"); // ... you can simply write: assertThat(homer).hasToString("Homer");
- Specified by:
hasToString
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
hasToString
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
expectedToString
- the expected String description of actual.- Returns:
- this assertion object.
-
is
Description copied from class:AbstractAssert
Verifies that the actual value satisfies the given condition. This method is an alias for
.ExtensionPoints.has(Condition)
- Specified by:
is
in interfaceExtensionPoints<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
is
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
isEqualTo
Description copied from class:AbstractAssert
Verifies that the actual value is equal to the given one.Example:
// assertions will pass assertThat("abc").isEqualTo("abc"); assertThat(new HashMap<String, Integer>()).isEqualTo(new HashMap<String, Integer>()); // assertions will fail assertThat("abc").isEqualTo("123"); assertThat(new ArrayList<String>()).isEqualTo(1);
- Specified by:
isEqualTo
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isEqualTo
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
expected
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isExactlyInstanceOf
Description copied from class:AbstractAssert
Verifies that the actual value is exactly an instance of the given type.Example:
// assertions will pass assertThat("abc").isExactlyInstanceOf(String.class); assertThat(new ArrayList<String>()).isExactlyInstanceOf(ArrayList.class); assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(HashMap.class); // assertions will fail assertThat(1).isExactlyInstanceOf(String.class); assertThat(new ArrayList<String>()).isExactlyInstanceOf(List.class); assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(Map.class);
- Specified by:
isExactlyInstanceOf
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isExactlyInstanceOf
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isIn
Description copied from class:AbstractAssert
Verifies that the actual value is present in the given values.Example:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya); // assertion will pass: assertThat(nenya).isIn(elvesRings); // assertion will fail: assertThat(oneRing).isIn(elvesRings);
- Specified by:
isIn
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isIn
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
values
- the given iterable to search the actual value in.- Returns:
this
assertion object.
-
isIn
Description copied from class:AbstractAssert
Verifies that the actual value is present in the given array of values.Example:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya }; // assertion will pass: assertThat(nenya).isIn(elvesRings); // assertion will fail: assertThat(oneRing).isIn(elvesRings);
- Specified by:
isIn
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isIn
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
values
- the given array to search the actual value in.- Returns:
this
assertion object.
-
isInstanceOf
Description copied from class:AbstractAssert
Verifies that the actual value is an instance of the given type.Example:
// assertions will pass assertThat("abc").isInstanceOf(String.class); assertThat(new HashMap<String, Integer>()).isInstanceOf(HashMap.class); assertThat(new HashMap<String, Integer>()).isInstanceOf(Map.class); // assertions will fail assertThat(1).isInstanceOf(String.class); assertThat(new ArrayList<String>()).isInstanceOf(LinkedList.class);
- Specified by:
isInstanceOf
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isInstanceOf
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isInstanceOfAny
Description copied from class:AbstractAssert
Verifies that the actual value is an instance of any of the given types.Example:
// assertions will pass assertThat("abc").isInstanceOfAny(String.class, Integer.class); assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, ArrayList.class); assertThat(new HashMap<String, Integer>()).isInstanceOfAny(TreeMap.class, Map.class); // assertions will fail assertThat(1).isInstanceOfAny(Double.class, Float.class); assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, Vector.class);
- Specified by:
isInstanceOfAny
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isInstanceOfAny
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNot
Description copied from class:AbstractAssert
Verifies that the actual value does not satisfy the given condition. This method is an alias for
.ExtensionPoints.doesNotHave(Condition)
- Specified by:
isNot
in interfaceExtensionPoints<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNot
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
isNotEqualTo
Description copied from class:AbstractAssert
Verifies that the actual value is not equal to the given one.Example:
// assertions will pass assertThat("abc").isNotEqualTo("123"); assertThat(new ArrayList<String>()).isNotEqualTo(1); // assertions will fail assertThat("abc").isNotEqualTo("abc"); assertThat(new HashMap<String, Integer>()).isNotEqualTo(new HashMap<String, Integer>());
- Specified by:
isNotEqualTo
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotEqualTo
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
other
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isNotExactlyInstanceOf
Description copied from class:AbstractAssert
Verifies that the actual value is not exactly an instance of given type.Example:
// assertions will pass assertThat(1).isNotExactlyInstanceOf(String.class); assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(List.class); assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(Map.class); // assertions will fail assertThat("abc").isNotExactlyInstanceOf(String.class); assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(ArrayList.class); assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(HashMap.class);
- Specified by:
isNotExactlyInstanceOf
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotExactlyInstanceOf
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotIn
Description copied from class:AbstractAssert
Verifies that the actual value is not present in the given values.Example:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya); // assertion will pass: assertThat(oneRing).isNotIn(elvesRings); // assertion will fail: assertThat(nenya).isNotIn(elvesRings);
- Specified by:
isNotIn
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotIn
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
values
- the given iterable to search the actual value in.- Returns:
this
assertion object.
-
isNotIn
Description copied from class:AbstractAssert
Verifies that the actual value is not present in the given array of values.Example:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya }; // assertion will pass: assertThat(oneRing).isNotIn(elvesRings); // assertion will fail: assertThat(nenya).isNotIn(elvesRings);
- Specified by:
isNotIn
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotIn
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
values
- the given array to search the actual value in.- Returns:
this
assertion object.
-
isNotInstanceOf
Description copied from class:AbstractAssert
Verifies that the actual value is not an instance of the given type.Example:
// assertions will pass assertThat(1).isNotInstanceOf(Double.class); assertThat(new ArrayList<String>()).isNotInstanceOf(LinkedList.class); // assertions will fail assertThat("abc").isNotInstanceOf(String.class); assertThat(new HashMap<String, Integer>()).isNotInstanceOf(HashMap.class); assertThat(new HashMap<String, Integer>()).isNotInstanceOf(Map.class);
- Specified by:
isNotInstanceOf
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotInstanceOf
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotInstanceOfAny
Description copied from class:AbstractAssert
Verifies that the actual value is not an instance of any of the given types.Example:
// assertions will pass assertThat(1).isNotInstanceOfAny(Double.class, Float.class); assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, Vector.class); // assertions will fail assertThat(1).isNotInstanceOfAny(Double.class, Integer.class); assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, ArrayList.class); assertThat(new HashMap<String, Integer>()).isNotInstanceOfAny(TreeMap.class, Map.class);
- Specified by:
isNotInstanceOfAny
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotInstanceOfAny
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotOfAnyClassIn
Description copied from class:AbstractAssert
Verifies that the actual value type is not in given types.Example:
// assertions will pass assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(Map.class, TreeMap.class); assertThat(new ArrayList<String>()).isNotOfAnyClassIn(LinkedList.class, List.class); // assertions will fail assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(HashMap.class, TreeMap.class); assertThat(new ArrayList<String>()).isNotOfAnyClassIn(ArrayList.class, LinkedList.class);
- Specified by:
isNotOfAnyClassIn
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotOfAnyClassIn
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotNull
Description copied from class:AbstractAssert
Verifies that the actual value is notnull
.Example:
// assertion will pass assertThat("abc").isNotNull(); assertThat(new HashMap<String, Integer>()).isNotNull(); // assertion will fail String value = null; assertThat(value).isNotNull();
-
isNotSameAs
Description copied from class:AbstractAssert
Verifies that the actual value is not the same as the given one, ie using == comparison.Example:
// Name is a class with first and last fields, two Names are equals if both first and last are equals. Name tyrion = new Name("Tyrion", "Lannister"); Name alias = tyrion; Name clone = new Name("Tyrion", "Lannister"); // assertions succeed: assertThat(clone).isNotSameAs(tyrion) .isEqualTo(tyrion); // assertion fails: assertThat(alias).isNotSameAs(tyrion);
- Specified by:
isNotSameAs
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isNotSameAs
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
other
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isOfAnyClassIn
Description copied from class:AbstractAssert
Verifies that the actual value type is in given types.Example:
// assertions will pass assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(HashMap.class, TreeMap.class); assertThat(new ArrayList<String>()).isOfAnyClassIn(ArrayList.class, LinkedList.class); // assertions will fail assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(TreeMap.class, Map.class); assertThat(new ArrayList<String>()).isOfAnyClassIn(LinkedList.class, List.class);
- Specified by:
isOfAnyClassIn
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isOfAnyClassIn
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isSameAs
Description copied from class:AbstractAssert
Verifies that the actual value is the same as the given one, ie using == comparison.Example:
// Name is a class with first and last fields, two Names are equals if both first and last are equals. Name tyrion = new Name("Tyrion", "Lannister"); Name alias = tyrion; Name clone = new Name("Tyrion", "Lannister"); // assertions succeed: assertThat(tyrion).isSameAs(alias) .isEqualTo(clone); // assertion fails: assertThat(tyrion).isSameAs(clone);
- Specified by:
isSameAs
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
isSameAs
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
expected
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
overridingErrorMessage
Description copied from class:AbstractAssert
Overrides AssertJ default error message by the given one.The new error message is built using
String.format(String, Object...)
if you provide args parameter (if you don't, the error message is taken as it is).Example :
assertThat(player.isRookie()).overridingErrorMessage("Expecting Player <%s> to be a rookie but was not.", player) .isTrue();
- Overrides:
overridingErrorMessage
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
newErrorMessage
- the error message that will replace the default one provided by Assertj.args
- the args used to fill error message as inString.format(String, Object...)
.- Returns:
- this assertion object.
-
usingDefaultComparator
Description copied from class:AbstractAssert
Revert to standard comparison for incoming assertion checks.This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.- Specified by:
usingDefaultComparator
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
usingDefaultComparator
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Returns:
this
assertion object.
-
usingComparator
Description copied from class:AbstractAssert
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy. Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
- Specified by:
usingComparator
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
usingComparator
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
withFailMessage
Description copied from class:AbstractAssert
Alternative method forAbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...)
- Overrides:
withFailMessage
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
newErrorMessage
- the error message that will replace the default one provided by Assertj.args
- the args used to fill error message as inString.format(String, Object...)
.- Returns:
- this assertion object.
-
withThreadDumpOnError
Description copied from class:AbstractAssert
In case of an assertion error, a thread dump will be printed toSystem.err
.Example :
will print a thread dump, something similar to this:assertThat("Messi").withThreadDumpOnError().isEqualTo("Ronaldo");
"JDWP Command Reader" java.lang.Thread.State: RUNNABLE "JDWP Event Helper Thread" java.lang.Thread.State: RUNNABLE "JDWP Transport Listener: dt_socket" java.lang.Thread.State: RUNNABLE "Signal Dispatcher" java.lang.Thread.State: RUNNABLE "Finalizer" java.lang.Thread.State: WAITING at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189) "Reference Handler" java.lang.Thread.State: WAITING at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:503) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133) "main" java.lang.Thread.State: RUNNABLE at sun.management.ThreadImpl.dumpThreads0(Native Method) at sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:446) at org.assertj.core.internal.Failures.threadDumpDescription(Failures.java:193) at org.assertj.core.internal.Failures.printThreadDumpIfNeeded(Failures.java:141) at org.assertj.core.internal.Failures.failure(Failures.java:91) at org.assertj.core.internal.Objects.assertEqual(Objects.java:314) at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:198) at org.assertj.examples.ThreadDumpOnErrorExample.main(ThreadDumpOnErrorExample.java:28)
- Specified by:
withThreadDumpOnError
in interfaceAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Overrides:
withThreadDumpOnError
in classAbstractAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Returns:
- this assertion object.
-
size
Returns anAssert
object that allows performing assertions on the size of theMap
under test.Once this method is called, the object under test is no longer the
Map
but its size, to perform assertions on theMap
, callAbstractMapSizeAssert.returnToMap()
.Example :
Map<Ring, TolkienCharacter> ringBearers = newHashMap(entry(oneRing, frodo), entry(nenya, galadriel), entry(narya, gandalf)); // assertion will pass: assertThat(ringBearers).size().isGreaterThan(1) .isLessThanOrEqualTo(3) returnToMap().contains(entry(oneRing, frodo), entry(nenya, galadriel), entry(narya, gandalf)); // assertion will fail: assertThat(ringBearers).size().isGreaterThan(5);
- Throws:
NullPointerException
- if the given map isnull
.
-
extracting
Extract the values of given keys from the map under test into an array, this new array becoming the object under test.For example, if you specify "id", "name" and "email" keys then the array will contain the map values for these keys, you can then perform array assertions on the extracted values.
If a given key is not present in the map under test, a null value is extracted.
Example:
Mapinvalid input: '<'String, Object> map = new HashMap<>(); map.put("name", "kawhi"); map.put("age", 25); assertThat(map).extracting("name", "age") .contains("kawhi", 25);
Note that the order of extracted keys value is consistent with the iteration order of the array under test.
Nested keys are not yet supported, passing "name.first" won't get a value for "name" and then try to extract "first" from the previously extracted value, instead it will simply look for a value under "name.first" key.
- Overrides:
extracting
in classAbstractObjectAssert<SELF extends AbstractMapAssert<SELF,
ACTUAL, K, V>, ACTUAL extends Map<K, V>> - Parameters:
keys
- the keys used to get values from the map under test- Returns:
- a new assertion object whose object under test is the array containing the extracted map values
-