Package org.fest.assertions
Class MapAssert
Understands assertions for
Map
s. To create a new instance of this class use the method
Assertions.assertThat(Map)
.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class org.fest.assertions.GenericAssert
actual
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Returns the number of elements in the actual
.Map
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
as
(Description description) Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
private boolean
describedAs
(String description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(String)
describedAs
(Description description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(Description)
doesNotSatisfy
(Condition<Map<?, ?>> condition) Verifies that the actual
does not satisfy the given condition.Map
static MapAssert.Entry
Creates a new map entry.private String
entryOrEntries
(List<MapAssert.Entry> found) excludes
(MapAssert.Entry... entries) Verifies that the actual
does not contain the given entries.Map
private void
failIfFound
(String description, Collection<?> found) private void
failIfNotFound
(String description, Collection<?> notFound) private String
hasSize
(int expected) Verifies that the number of elements in the actual
is equal to the given one.Map
includes
(MapAssert.Entry... entries) Verifies that the actual
contains the given entries.Map
Alias for
.satisfies(Condition)
Verifies that the actual
is equal to the given one.Map
Alias for
.doesNotSatisfy(Condition)
Verifies that the actual
contains at least on element.Map
isNotEqualTo
(Map<?, ?> other) Verifies that the actual
is not equal to the given one.Map
Verifies that the actual
is notMap
null
.isNotSameAs
(Map<?, ?> other) Verifies that the actual
is not the same as the given one.Map
Verifies that the actual
is the same as the given one.Map
overridingErrorMessage
(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actual
satisfies the given condition.Map
private void
Methods inherited from class org.fest.assertions.GroupAssert
assertHasSize, assertIsNotEmpty, isEmpty, isNullOrEmpty
Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNull
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
-
Field Details
-
ENTRY
- See Also:
-
ENTRIES
- See Also:
-
-
Constructor Details
-
MapAssert
Creates a newMapAssert
.- Parameters:
actual
- the target to verify.
-
-
Method Details
-
as
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as("name").isEqualTo("Frodo");
- Specified by:
as
in classGroupAssert<Map<?,
?>> - Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for
, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(String)
For example:
assertThat(val).describedAs("name").isEqualTo("Frodo");
- Specified by:
describedAs
in classGroupAssert<Map<?,
?>> - Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
as
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionError
For example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
- Specified by:
as
in classGroupAssert<Map<?,
?>> - Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
describedAs
Alias for
, since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.GenericAssert.as(Description)
For example:
assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
- Specified by:
describedAs
in classGroupAssert<Map<?,
?>> - Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
includes
Verifies that the actual
contains the given entries.Map
Example:
// static import org.fest.assertions.Assertions.*; // static import org.fest.assertions.MapAssert.*; assertThat(myMap).
includes
(entry
("jedi", yoda),entry
("sith", anakin));- Parameters:
entries
- the given entries.- Returns:
- this assertion error.
- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actualMap
does not contain any of the given entries.NullPointerException
- if the given array of entries isnull
.NullPointerException
- if any of the entries in the given array isnull
.
-
excludes
Verifies that the actual
does not contain the given entries.Map
Example:
// static import org.fest.assertions.Assertions.*; // static import org.fest.assertions.MapAssert.*; assertThat(myMap).
excludes
(entry
("jedi", yoda),entry
("sith", anakin));- Parameters:
entries
- the given entries.- Returns:
- this assertion error.
- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the actualMap
contains any of the given entries.NullPointerException
- if the given array of entries isnull
.NullPointerException
- if any of the entries in the given array isnull
.
-
containsEntry
-
entryOrEntries
-
entry
Creates a new map entry.- Parameters:
key
- the key of the entry.value
- the value of the entry.- Returns:
- the created entry.
- See Also:
-
failIfNotFound
-
validate
-
failIfFound
-
hasSize
Verifies that the number of elements in the actual
is equal to the given one.Map
- Specified by:
hasSize
in classGroupAssert<Map<?,
?>> - Parameters:
expected
- the expected number of elements in the actualMap
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual map isnull
.AssertionError
- if the number of elements of the actualMap
is not equal to the given one.
-
formattedActual
-
isEqualTo
Verifies that the actual
is equal to the given one.Map
- Specified by:
isEqualTo
in classGenericAssert<Map<?,
?>> - Parameters:
expected
- the given map to compare the actualMap
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualMap
is not equal to the given one.
-
isNotEmpty
Verifies that the actual
contains at least on element.Map
- Specified by:
isNotEmpty
in classGroupAssert<Map<?,
?>> - Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualMap
is empty.
-
isNotEqualTo
Verifies that the actual
is not equal to the given one.Map
- Specified by:
isNotEqualTo
in classGenericAssert<Map<?,
?>> - Parameters:
other
- the given map to compare the actualMap
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualMap
is equal to the given one.
-
isNotNull
Verifies that the actual
is notMap
null
.- Specified by:
isNotNull
in classGenericAssert<Map<?,
?>> - Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualMap
isnull
.
-
isNotSameAs
Verifies that the actual
is not the same as the given one.Map
- Specified by:
isNotSameAs
in classGenericAssert<Map<?,
?>> - Parameters:
other
- the given map to compare the actualMap
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualMap
is the same as the given one.
-
isSameAs
Verifies that the actual
is the same as the given one.Map
- Specified by:
isSameAs
in classGenericAssert<Map<?,
?>> - Parameters:
expected
- the given map to compare the actualMap
to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualMap
is not the same as the given one.
-
satisfies
Verifies that the actual
satisfies the given condition.Map
- Specified by:
satisfies
in classGenericAssert<Map<?,
?>> - Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualMap
does not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actual
does not satisfy the given condition.Map
- Specified by:
doesNotSatisfy
in classGenericAssert<Map<?,
?>> - Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualMap
satisfies the given condition.- See Also:
-
is
Alias for
.satisfies(Condition)
- Specified by:
is
in classGenericAssert<Map<?,
?>> - Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualMap
does not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for
.doesNotSatisfy(Condition)
- Specified by:
isNot
in classGenericAssert<Map<?,
?>> - Parameters:
condition
- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if the actualMap
satisfies the given condition.- Since:
- 1.2
-
actualGroupSize
protected int actualGroupSize()Returns the number of elements in the actual
.Map
- Specified by:
actualGroupSize
in classGroupAssert<Map<?,
?>> - Returns:
- the number of elements in the actual
.Map
-
overridingErrorMessage
Replaces the default message displayed in case of a failure with the given one.For example, the following assertion:
assertThat("Hello").isEqualTo("Bye");
will fail with the default message "expected:<'[Bye]'> but was:<'[Hello]'>."We can replace this message with our own:
assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye");
in this case, the assertion will fail showing the message "'Hello' should be equal to 'Bye'".- Specified by:
overridingErrorMessage
in classGroupAssert<Map<?,
?>> - Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-