Package org.fest.assertions
Class ObjectGroupAssert<T>
java.lang.Object
org.fest.assertions.Assert
org.fest.assertions.GenericAssert<T>
org.fest.assertions.GroupAssert<T>
org.fest.assertions.ItemGroupAssert<T>
org.fest.assertions.ObjectGroupAssert<T>
- Type Parameters:
T
- the type of object implementations of this template can verify.
- Direct Known Subclasses:
CollectionAssert
,ListAssert
,ObjectArrayAssert
Understands a template for assertion methods related to arrays or collections.
- Since:
- 1.3
-
Field Summary
Fields inherited from class org.fest.assertions.GenericAssert
actual
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ObjectGroupAssert
(T actual) Creates a newObjectGroupAssert
. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ObjectGroupAssert<T>
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails.AssertionError
protected abstract ObjectGroupAssert<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 abstract ObjectGroupAssert<T>
Verifies that the actual group of objects contains the given objects.protected abstract ObjectGroupAssert<T>
containsOnly
(Object... objects) Verifies that the actual group of objects contains the given objects only, in any order.protected abstract ObjectGroupAssert<T>
describedAs
(String description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(String)
protected abstract ObjectGroupAssert<T>
describedAs
(Description description) Alias for
, since "as" is a keyword in Groovy.GenericAssert.as(Description)
protected abstract ObjectGroupAssert<T>
Verifies that the actual group of objects does not have duplicates.protected abstract ObjectGroupAssert<T>
Verifies that the actual group of objects does not contain the given objects.protected abstract ObjectGroupAssert<T>
onProperty
(String propertyName) Creates a new group of objects whose target collection contains the values of the given property name from the elements of the actual group of objects.protected abstract ObjectGroupAssert<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.ItemGroupAssert
actualAsList, actualAsSet, assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, asSet, validateIsNotNull
Methods inherited from class org.fest.assertions.GroupAssert
actualGroupSize, assertHasSize, assertIsNotEmpty, hasSize, isEmpty, isNotEmpty, isNullOrEmpty
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
-
ObjectGroupAssert
Creates a newObjectGroupAssert
.- Parameters:
actual
- the target to verify.
-
-
Method Details
-
contains
Verifies that the actual group of objects contains the given objects.- Parameters:
objects
- the objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual group of objects isnull
.NullPointerException
- if the given array isnull
.AssertionError
- if the actual group of objects does not contain the given objects.
-
containsOnly
Verifies that the actual group of objects contains the given objects only, in any order.- Parameters:
objects
- the objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual group of objects isnull
.NullPointerException
- if the given group of objects isnull
.AssertionError
- if the actual group of objects does not contain the given objects, or if the actual group of objects contains elements other than the ones specified.
-
excludes
Verifies that the actual group of objects does not contain the given objects.- Parameters:
objects
- the objects that the group of objects should exclude.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual group of objects isnull
.NullPointerException
- if the given array isnull
.AssertionError
- if the actual group of objects contains any of the given objects.
-
doesNotHaveDuplicates
Verifies that the actual group of objects does not have duplicates.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual group of objects isnull
.AssertionError
- if the actual group of objects has duplicates.
-
onProperty
Creates a new group of objects whose target collection contains the values of the given property name from the elements of the actual group of objects. Property access works with both simple properties likePerson.age
and nested propertiesPerson.father.age
.For example, let's say we have a collection of
Person
objects and you want to verify their age:assertThat(persons).onProperty("age").containsOnly(25, 16, 44, 37); // simple property assertThat(persons).onProperty("father.age").containsOnly(55, 46, 74, 62); // nested property
- Parameters:
propertyName
- the name of the property to extract values from the actual collection to build a new group of objects.- Returns:
- a new group of objects containing the values of the given property name from the elements of the actual group of objects.
- Throws:
AssertionError
- if the actual group of objects isnull
.org.fest.util.IntrospectionError
- if an element in the given collection does not have a matching property.- Since:
- 1.3
-
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<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 classGroupAssert<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 classGroupAssert<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 classGroupAssert<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 classGroupAssert<T>
- Parameters:
message
- the given error message, which will replace the default one.- Returns:
- this assertion.
-