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,Map.Entry<? extends K,? extends V>>
Maps.actual, info, myself| Constructor and Description |
|---|
AbstractMapAssert(A actual,
Class<?> selfType) |
| Modifier and Type | Method and Description |
|---|---|
S |
as(Description description)
Sets the description of the assertion that is going to be called after.
|
S |
as(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
S |
contains(Map.Entry<? extends K,? extends V>... entries)
Verifies that the actual map contains the given entries, in any order.
|
S |
containsAllEntriesOf(Map<? extends K,? extends V> other)
Verifies that the actual map contains all entries of the given map, in any order.
|
S |
containsEntry(K key,
V value)
Verifies that the actual map contains the given entry.
|
S |
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 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(Map.Entry<? 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 |
describedAs(Description description)
Sets the description of the assertion that is going to be called after.
|
S |
describedAs(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
S |
doesNotContain(Map.Entry<? 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 |
doesNotHave(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition.
|
S |
doesNotHaveSameClassAs(Object other)
Verifies that the actual value does not have the same class as the given object.
|
S |
has(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition.
|
S |
hasSameClassAs(Object other)
Verifies that the actual value has the same class as the given object.
|
S |
hasSameSizeAs(Iterable<?> other)
Verifies that the actual map has the same size as the 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 map has the same size as given array.
|
S |
hasSize(int expected)
Verifies that the number of values in the
Map is equal to the given one. |
S |
hasToString(String expectedToString)
Verifies that actual
actual.toString() is equal to the given String. |
S |
is(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition.
|
void |
isEmpty()
Verifies that the
Map is empty. |
S |
isEqualTo(Object expected)
Verifies that the actual value is equal to the given one.
|
S |
isExactlyInstanceOf(Class<?> type)
Verifies that the actual value is exactly an instance of the given type.
|
S |
isIn(Iterable<?> values)
Verifies that the actual value is present in the given values.
|
S |
isIn(Object... values)
Verifies that the actual value is present in the given array of values.
|
S |
isInstanceOf(Class<?> type)
Verifies that the actual value is an instance of the given type.
|
S |
isInstanceOfAny(Class<?>... types)
Verifies that the actual value is an instance of any of the given types.
|
S |
isNot(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition.
|
S |
isNotEmpty()
Verifies that the
Map is not empty. |
S |
isNotEqualTo(Object other)
Verifies that the actual value is not equal to the given one.
|
S |
isNotExactlyInstanceOf(Class<?> type)
Verifies that the actual value is not exactly an instance of given type.
|
S |
isNotIn(Iterable<?> values)
Verifies that the actual value is not present in the given values.
|
S |
isNotIn(Object... values)
Verifies that the actual value is not present in the given array of values.
|
S |
isNotInstanceOf(Class<?> type)
Verifies that the actual value is not an instance of the given type.
|
S |
isNotInstanceOfAny(Class<?>... types)
Verifies that the actual value is not an instance of any of the given types.
|
S |
isNotNull()
Verifies that the actual value is not
null. |
S |
isNotOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is not in given types.
|
S |
isNotSameAs(Object other)
Verifies that the actual value is not the same as the given one, ie using == comparison.
|
void |
isNullOrEmpty()
Verifies that the
Map is null or empty. |
S |
isOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is in given types.
|
S |
isSameAs(Object expected)
Verifies that the actual value is the same as the given one, ie using == comparison.
|
S |
overridingErrorMessage(String newErrorMessage,
Object... args)
Overrides AssertJ default error message by the given one.
|
AbstractMapSizeAssert<S,A,K,V> |
size()
Return an
Assert object that allows to perform assertions on the size of the Map under test. |
S |
usingComparator(Comparator<? super A> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
S |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
S |
usingDefaultElementComparator()
Deprecated.
Custom element Comparator is not supported for MapEntry comparison.
|
S |
usingElementComparator(Comparator<? super Map.Entry<? extends K,? extends V>> customComparator)
Deprecated.
Custom element Comparator is not supported for MapEntry comparison.
|
S |
withFailMessage(String newErrorMessage,
Object... args)
Alternative method for
AbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...) |
S |
withThreadDumpOnError()
In case of assertion error, the thread dump will be printed on
System.err. |
asList, asString, descriptionText, equals, failWithMessage, getWritableAssertionInfo, hashCode, inBinary, inHexadecimal, isNull, matches, matches, satisfies, setCustomRepresentation, throwAssertionError, withRepresentationpublic void isNullOrEmpty()
Map is null 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()
isNullOrEmpty in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,Map.Entry<? extends K,? extends V>>AssertionError - if the Map is not null or not empty.public void isEmpty()
Map 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();
isEmpty in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,Map.Entry<? extends K,? extends V>>AssertionError - if the Map of values is not empty.public S isNotEmpty()
Map 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();
isNotEmpty in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,Map.Entry<? extends K,? extends V>>this assertion object.AssertionError - if the Map is empty.public S hasSize(int expected)
Map 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);
hasSize in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,Map.Entry<? extends K,? extends V>>expected - the expected number of values in the Map.this assertion object.AssertionError - if the number of values of the Map is not equal to the given one.public S hasSameSizeAs(Object other)
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'});hasSameSizeAs in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,Map.Entry<? extends K,? extends V>>array - the array to compare size with actual group.this assertion object.AssertionError - if the actual group is null.AssertionError - if the array parameter is null or is not a true array.AssertionError - if actual group and given array don't have the same size.public S hasSameSizeAs(Iterable<?> other)
Iterable.
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'));hasSameSizeAs in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,Map.Entry<? extends K,? extends V>>other - the Iterable to compare size with actual group.this assertion object.AssertionError - if the actual map is null.AssertionError - if the other Iterable is null.AssertionError - if the actual map and the given Iterable don't have the same sizepublic S hasSameSizeAs(Map<?,?> other)
Map.
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);other - the Map to compare size with actual mapthis assertion objectNullPointerException - if the other Map is nullAssertionError - if the actual map is nullAssertionError - if the actual map and the given Map don't have the same sizepublic S contains(Map.Entry<? extends K,? extends V>... 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).contains(entry(oneRing, frodo), entry(nenya, galadriel));
// 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));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 containsAllEntriesOf(Map<? extends K,? extends V> other)
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);the - map with the given entries.this assertion object.NullPointerException - if the given argument is null.NullPointerException - if any of the entries in the given map 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<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);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(Map.Entry<? extends K,? extends V>... 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));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<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);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<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);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<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);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<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);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<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);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<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);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<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);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<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);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<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);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(Map.Entry<? extends K,? extends V>... entries)
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));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(Map.Entry<? 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 order 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 Map.Entry<? extends K,? extends V>> customComparator)
usingElementComparator in interface EnumerableAssert<S extends AbstractMapAssert<S,A,K,V>,Map.Entry<? 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>,Map.Entry<? extends K,? extends V>>this assertion object.UnsupportedOperationException - if this method is called.public S as(String description, Object... args)
AbstractAssertYou 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]>");
}as in interface Descriptable<S extends AbstractMapAssert<S,A,K,V>>as in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>description - the new description to set.args - optional parameter if description is a format String.this object.Descriptable.describedAs(String, Object...)public S as(Description description)
AbstractAssertYou 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.
as in interface Descriptable<S extends AbstractMapAssert<S,A,K,V>>as in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>description - the new description to set.this object.Descriptable.describedAs(Description)public S describedAs(Description description)
AbstractAssertYou 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.
describedAs in interface Descriptable<S extends AbstractMapAssert<S,A,K,V>>describedAs in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>description - the new description to set.this object.public S describedAs(String description, Object... args)
AbstractAssertYou 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...)
describedAs in interface Descriptable<S extends AbstractMapAssert<S,A,K,V>>describedAs in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>description - the new description to set.this object.public S doesNotHave(Condition<? super A> condition)
AbstractAssertExtensionPoints.isNot(Condition).doesNotHave in interface ExtensionPoints<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>doesNotHave in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.isNot(Condition)public S doesNotHaveSameClassAs(Object other)
AbstractAssertExample:
// 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>());doesNotHaveSameClassAs in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>doesNotHaveSameClassAs in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>other - the object to check type against.public S has(Condition<? super A> condition)
AbstractAssertExtensionPoints.is(Condition)
.has in interface ExtensionPoints<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>has in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.is(Condition)public S hasSameClassAs(Object other)
AbstractAssertExample:
// 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>());hasSameClassAs in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>hasSameClassAs in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>other - the object to check type against.public S hasToString(String expectedToString)
AbstractAssertactual.toString() is equal to the given String.
Example :
CartoonCaracter homer = new CartoonCaracter("Homer");
// Instead of writing ...
assertThat(homer.toString()).isEqualTo("Homer");
// ... you can simply write:
assertThat(homer).hasToString("Homer");hasToString in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>hasToString in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>expectedToString - the expected String description of actual.public S is(Condition<? super A> condition)
AbstractAssertExtensionPoints.has(Condition).is in interface ExtensionPoints<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>is in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.is(Condition)public S isEqualTo(Object expected)
AbstractAssertExample:
// 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);isEqualTo in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isEqualTo in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>expected - the given value to compare the actual value to.this assertion object.public S isExactlyInstanceOf(Class<?> type)
AbstractAssertExample:
// 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);isExactlyInstanceOf in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isExactlyInstanceOf in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>type - the type to check the actual value against.public S isIn(Iterable<?> values)
AbstractAssertExample:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertion will pass:
assertThat(nenya).isIn(elvesRings);
// assertion will fail:
assertThat(oneRing).isIn(elvesRings);public S isIn(Object... values)
AbstractAssertExample:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
// assertion will pass:
assertThat(nenya).isIn(elvesRings);
// assertion will fail:
assertThat(oneRing).isIn(elvesRings);public S isInstanceOf(Class<?> type)
AbstractAssertExample:
// 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);isInstanceOf in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isInstanceOf in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>type - the type to check the actual value against.public S isInstanceOfAny(Class<?>... types)
AbstractAssertExample:
// 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);isInstanceOfAny in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isInstanceOfAny in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>types - the types to check the actual value against.public S isNot(Condition<? super A> condition)
AbstractAssertExtensionPoints.doesNotHave(Condition).isNot in interface ExtensionPoints<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNot in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.isNot(Condition)public S isNotEqualTo(Object other)
AbstractAssertExample:
// 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>());isNotEqualTo in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNotEqualTo in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>other - the given value to compare the actual value to.this assertion object.public S isNotExactlyInstanceOf(Class<?> type)
AbstractAssertExample:
// 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);isNotExactlyInstanceOf in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNotExactlyInstanceOf in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>type - the type to check the actual value against.public S isNotIn(Iterable<?> values)
AbstractAssertExample:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertion will pass:
assertThat(oneRing).isNotIn(elvesRings);
// assertion will fail:
assertThat(nenya).isNotIn(elvesRings);isNotIn in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNotIn in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>values - the given iterable to search the actual value in.this assertion object.public S isNotIn(Object... values)
AbstractAssertExample:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
// assertion will pass:
assertThat(oneRing).isNotIn(elvesRings);
// assertion will fail:
assertThat(nenya).isNotIn(elvesRings);public S isNotInstanceOf(Class<?> type)
AbstractAssertExample:
// 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);isNotInstanceOf in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNotInstanceOf in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>type - the type to check the actual value against.public S isNotInstanceOfAny(Class<?>... types)
AbstractAssertExample:
// 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);isNotInstanceOfAny in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNotInstanceOfAny in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>types - the types to check the actual value against.public S isNotOfAnyClassIn(Class<?>... types)
AbstractAssertExample:
// 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);isNotOfAnyClassIn in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNotOfAnyClassIn in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>types - the types to check the actual value against.public S isNotNull()
AbstractAssertnull.
Example:
// assertion will pass
assertThat("abc").isNotNull();
assertThat(new HashMap<String, Integer>()).isNotNull();
// assertion will fail
String value = null;
assertThat(value).isNotNull();public S isNotSameAs(Object other)
AbstractAssertExample:
// 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);isNotSameAs in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isNotSameAs in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>other - the given value to compare the actual value to.this assertion object.public S isOfAnyClassIn(Class<?>... types)
AbstractAssertExample:
// 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);isOfAnyClassIn in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isOfAnyClassIn in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>types - the types to check the actual value against.public S isSameAs(Object expected)
AbstractAssertExample:
// 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);isSameAs in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>isSameAs in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>expected - the given value to compare the actual value to.this assertion object.public S overridingErrorMessage(String newErrorMessage, Object... args)
AbstractAssert
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();overridingErrorMessage in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>newErrorMessage - the error message that will replace the default one provided by Assertj.args - the args used to fill error message as in String.format(String, Object...).public S usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator).
usingDefaultComparator in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>usingDefaultComparator in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>this assertion object.public S usingComparator(Comparator<? super A> customComparator)
AbstractAssertCustom 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);usingComparator in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>usingComparator in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>customComparator - the comparator to use for incoming assertion checks.this assertion object.public S withFailMessage(String newErrorMessage, Object... args)
AbstractAssertAbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...)withFailMessage in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>newErrorMessage - the error message that will replace the default one provided by Assertj.args - the args used to fill error message as in String.format(String, Object...).public S withThreadDumpOnError()
AbstractAssertSystem.err.
Example :
assertThat("Messi").withThreadDumpOnError().isEqualTo("Ronaldo");
will print the thread dump, something looking like:
"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)withThreadDumpOnError in interface Assert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>withThreadDumpOnError in class AbstractAssert<S extends AbstractMapAssert<S,A,K,V>,A extends Map<K,V>>public AbstractMapSizeAssert<S,A,K,V> size()
Assert object that allows to perform assertions on the size of the Map under test.
Once this method is called, the object under test is no more the initial Map but its size,
to perform assertions on the initial Map, call AbstractMapSizeAssert.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);NullPointerException - if the given map is null.Copyright © 2014–2016 AssertJ. All rights reserved.