Package org.fest.assertions
Class GroupAssert<T>
java.lang.Object
org.fest.assertions.Assert
org.fest.assertions.GenericAssert<T>
org.fest.assertions.GroupAssert<T>
- Type Parameters:
T
- the type of object implementations of this template can verify.
- Direct Known Subclasses:
ItemGroupAssert
,MapAssert
,StringAssert
Understands a template for assertion methods related to classes representing groups of values.
-
Field Summary
Fields inherited from class org.fest.assertions.GenericAssert
actual
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
Returns the size of the actual group of values (array, collection, etc.)protected abstract GroupAssert<T>
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
protected abstract GroupAssert<T>
as
(Description description) Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
protected final void
assertHasSize
(int expected) Verifies that the number of elements in the actual group of values is equal to the given one.protected final void
Verifies that the actual group of values contains at least one element.protected abstract GroupAssert<T>
describedAs
(String description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(String)
protected abstract GroupAssert<T>
describedAs
(Description description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(Description)
private boolean
protected abstract GroupAssert<T>
hasSize
(int expected) Verifies that the number of values in the actual group is equal to the given one.void
isEmpty()
Verifies that the actual group of values is empty.protected abstract GroupAssert<T>
Verifies that the actual group contains at least on value.void
Verifies that the actual group of values isnull
or empty.protected abstract GroupAssert<T>
overridingErrorMessage
(String message) Replaces the default message displayed in case of a failure with the given one.Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, doesNotSatisfy, is, isEqualTo, isNot, isNotEqualTo, isNotNull, isNotSameAs, isNull, isSameAs, satisfies
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
-
Constructor Details
-
GroupAssert
Creates a new
.GroupAssert
- Parameters:
actual
- the target to verify.
-
-
Method Details
-
isNullOrEmpty
public void isNullOrEmpty()Verifies that the actual group of values isnull
or empty.- Throws:
AssertionError
- if the actual group of values is notnull
or not empty.
-
isEmpty
public void isEmpty()Verifies that the actual group of values is empty.- Throws:
AssertionError
- if the actual group of values isnull
or not empty.
-
hasElements
private boolean hasElements() -
isNotEmpty
Verifies that the actual group contains at least on value.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual group isnull
or empty.
-
assertIsNotEmpty
protected final void assertIsNotEmpty()Verifies that the actual group of values contains at least one element.- Throws:
AssertionError
- if the actual group of values isnull
.AssertionError
- if the actual group of values is empty.
-
hasSize
Verifies that the number of values in the actual group is equal to the given one.- Parameters:
expected
- the expected number of values in the actual group.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the number of values of the actual group is not equal to the given one.
-
assertHasSize
protected final void assertHasSize(int expected) Verifies that the number of elements in the actual group of values is equal to the given one.- Parameters:
expected
- the expected number of elements in the actual group of values.- Throws:
AssertionError
- if the actual group of values isnull
.AssertionError
- if the number of elements of the actual group of values is not equal to the given one.
-
actualGroupSize
protected abstract int actualGroupSize()Returns the size of the actual group of values (array, collection, etc.)- Returns:
- the size of the actual group of values.
-
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 classGenericAssert<T>
- 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 classGenericAssert<T>
- 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 classGenericAssert<T>
- 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 classGenericAssert<T>
- Parameters:
description
- the description of the actual value.- Returns:
- this assertion object.
-
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 classGenericAssert<T>
- Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-