Package org.fest.assertions
Class MapAssert
Understands assertions for
Maps. 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 intReturns the number of elements in the actual.MapSets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErroras(Description description) Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErrorprivate booleandescribedAs(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 actualdoes not satisfy the given condition.Mapstatic MapAssert.EntryCreates a new map entry.private StringentryOrEntries(List<MapAssert.Entry> found) excludes(MapAssert.Entry... entries) Verifies that the actualdoes not contain the given entries.Mapprivate voidfailIfFound(String description, Collection<?> found) private voidfailIfNotFound(String description, Collection<?> notFound) private StringhasSize(int expected) Verifies that the number of elements in the actualis equal to the given one.Mapincludes(MapAssert.Entry... entries) Verifies that the actualcontains the given entries.MapAlias for.satisfies(Condition)Verifies that the actualis equal to the given one.MapAlias for.doesNotSatisfy(Condition)Verifies that the actualcontains at least on element.MapisNotEqualTo(Map<?, ?> other) Verifies that the actualis not equal to the given one.MapVerifies that the actualis notMapnull.isNotSameAs(Map<?, ?> other) Verifies that the actualis not the same as the given one.MapVerifies that the actualis the same as the given one.MapoverridingErrorMessage(String message) Replaces the default message displayed in case of a failure with the given one.Verifies that the actualsatisfies the given condition.Mapprivate voidMethods inherited from class org.fest.assertions.GroupAssert
assertHasSize, assertIsNotEmpty, isEmpty, isNullOrEmptyMethods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNullMethods 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 anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as("name").isEqualTo("Frodo");- Specified by:
asin 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:
describedAsin 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 anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");- Specified by:
asin 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:
describedAsin classGroupAssert<Map<?,?>> - Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
includes
Verifies that the actualcontains the given entries.MapExample:
// 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 actualMapdoes 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 actualdoes not contain the given entries.MapExample:
// 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 actualMapcontains 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 actualis equal to the given one.Map- Specified by:
hasSizein 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 actualMapis not equal to the given one.
-
formattedActual
-
isEqualTo
Verifies that the actualis equal to the given one.Map- Specified by:
isEqualToin classGenericAssert<Map<?,?>> - Parameters:
expected- the given map to compare the actualMapto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualMapis not equal to the given one.
-
isNotEmpty
Verifies that the actualcontains at least on element.Map- Specified by:
isNotEmptyin classGroupAssert<Map<?,?>> - Returns:
- this assertion object.
- Throws:
AssertionError- if the actualMapis empty.
-
isNotEqualTo
Verifies that the actualis not equal to the given one.Map- Specified by:
isNotEqualToin classGenericAssert<Map<?,?>> - Parameters:
other- the given map to compare the actualMapto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualMapis equal to the given one.
-
isNotNull
Verifies that the actualis notMapnull.- Specified by:
isNotNullin classGenericAssert<Map<?,?>> - Returns:
- this assertion object.
- Throws:
AssertionError- if the actualMapisnull.
-
isNotSameAs
Verifies that the actualis not the same as the given one.Map- Specified by:
isNotSameAsin classGenericAssert<Map<?,?>> - Parameters:
other- the given map to compare the actualMapto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualMapis the same as the given one.
-
isSameAs
Verifies that the actualis the same as the given one.Map- Specified by:
isSameAsin classGenericAssert<Map<?,?>> - Parameters:
expected- the given map to compare the actualMapto.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualMapis not the same as the given one.
-
satisfies
Verifies that the actualsatisfies the given condition.Map- Specified by:
satisfiesin classGenericAssert<Map<?,?>> - Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualMapdoes not satisfy the given condition.- See Also:
-
doesNotSatisfy
Verifies that the actualdoes not satisfy the given condition.Map- Specified by:
doesNotSatisfyin classGenericAssert<Map<?,?>> - Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualMapsatisfies the given condition.- See Also:
-
is
Alias for.satisfies(Condition)- Specified by:
isin classGenericAssert<Map<?,?>> - Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualMapdoes not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for.doesNotSatisfy(Condition)- Specified by:
isNotin classGenericAssert<Map<?,?>> - Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actualMapsatisfies the given condition.- Since:
- 1.2
-
actualGroupSize
protected int actualGroupSize()Returns the number of elements in the actual.Map- Specified by:
actualGroupSizein 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:
overridingErrorMessagein classGroupAssert<Map<?,?>> - Parameters:
message- the given error message, which will replace the default one.- Returns:
- this assertion.
-