|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fest.assertions.Assert
org.fest.assertions.GenericAssert<T>
org.fest.assertions.GroupAssert<T>
org.fest.assertions.ItemGroupAssert<T>
org.fest.assertions.ObjectGroupAssert<Collection<?>>
org.fest.assertions.CollectionAssert
public class CollectionAssert
Understands assertions for collections. To create a new instance of this class use the method
.
Assertions.assertThat(Collection)
Field Summary |
---|
Fields inherited from class org.fest.assertions.GenericAssert |
---|
actual |
Constructor Summary | |
---|---|
protected |
CollectionAssert(Collection<?> actual)
Creates a new CollectionAssert . |
Method Summary | |
---|---|
protected List<Object> |
actualAsList()
Returns the actual value as a List . |
protected Set<Object> |
actualAsSet()
Returns the actual value as a Set . |
protected int |
actualGroupSize()
Returns the number of elements in the actual collection. |
CollectionAssert |
as(Description description)
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. |
CollectionAssert |
as(String description)
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. |
CollectionAssert |
contains(Object... objects)
Verifies that the actual collection contains the given objects. |
CollectionAssert |
containsOnly(Object... objects)
Verifies that the actual collection contains the given objects only. |
CollectionAssert |
describedAs(Description description)
Alias for , since "as" is a keyword in
Groovy. |
CollectionAssert |
describedAs(String description)
Alias for , since "as" is a keyword in
Groovy. |
CollectionAssert |
doesNotHaveDuplicates()
Verifies that the actual collection does not have duplicates. |
CollectionAssert |
doesNotSatisfy(Condition<Collection<?>> condition)
Verifies that the actual collection does not satisfy the given condition. |
CollectionAssert |
excludes(Object... objects)
Verifies that the actual collection does not contain the given objects. |
CollectionAssert |
hasSize(int expected)
Verifies that the number of elements in the actual collection is equal to the given one. |
CollectionAssert |
is(Condition<Collection<?>> condition)
Alias for . |
CollectionAssert |
isEqualTo(Collection<?> expected)
Verifies that the actual collection is equal to the given one. |
CollectionAssert |
isNot(Condition<Collection<?>> condition)
Alias for . |
CollectionAssert |
isNotEmpty()
Verifies that the actual collection contains at least on element. |
CollectionAssert |
isNotEqualTo(Collection<?> other)
Verifies that the actual collection is not equal to the given one. |
CollectionAssert |
isNotNull()
Verifies that the actual collection is not null . |
CollectionAssert |
isNotSameAs(Collection<?> other)
Verifies that the actual collection is not the same as the given one. |
CollectionAssert |
isSameAs(Collection<?> expected)
Verifies that the actual collection is the same as the given one. |
CollectionAssert |
onProperty(String propertyName)
Creates a new instance of whose target collection contains the values of the
given property name from the elements of this CollectionAssert 's collection. |
CollectionAssert |
overridingErrorMessage(String message)
Replaces the default message displayed in case of a failure with the given one. |
CollectionAssert |
satisfies(Condition<Collection<?>> condition)
Verifies that the actual collection satisfies the given condition. |
Methods inherited from class org.fest.assertions.ItemGroupAssert |
---|
assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, asSet, validateIsNotNull |
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 |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected CollectionAssert(Collection<?> actual)
CollectionAssert
.
actual
- the target to verify.Method Detail |
---|
public CollectionAssert contains(Object... objects)
contains
in class ObjectGroupAssert<Collection<?>>
objects
- the objects to look for.
AssertionError
- if the actual collection is null
.
NullPointerException
- if the given array is null
.
AssertionError
- if the actual collection does not contain the given objects.public CollectionAssert containsOnly(Object... objects)
containsOnly
in class ObjectGroupAssert<Collection<?>>
objects
- the objects to look for.
AssertionError
- if the actual collection is null
.
NullPointerException
- if the given array is null
.
AssertionError
- if the actual collection does not contain the given objects, or if the actual collection
contains elements other than the ones specified.public CollectionAssert excludes(Object... objects)
excludes
in class ObjectGroupAssert<Collection<?>>
objects
- the objects that the collection should exclude.
AssertionError
- if the actual collection is null
.
NullPointerException
- if the given array is null
.
AssertionError
- if the actual collection contains any of the given objects.public CollectionAssert doesNotHaveDuplicates()
doesNotHaveDuplicates
in class ObjectGroupAssert<Collection<?>>
AssertionError
- if the actual collection is null
.
AssertionError
- if the actual collection has duplicates.public CollectionAssert as(String description)
AssertionError
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion
failure will not show the provided description.
For example:
assertThat(val).as("name").isEqualTo("Frodo");
as
in class ObjectGroupAssert<Collection<?>>
description
- the description of the actual value.
public CollectionAssert describedAs(String description)
GenericAssert.as(String)
, 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.
For example:
assertThat(val).describedAs("name").isEqualTo("Frodo");
describedAs
in class ObjectGroupAssert<Collection<?>>
description
- the description of the actual value.
public CollectionAssert as(Description description)
AssertionError
thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion
failure will not show the provided description.
For example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
as
in class ObjectGroupAssert<Collection<?>>
description
- the description of the actual value.
public CollectionAssert describedAs(Description description)
GenericAssert.as(Description)
, 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.
For example:
assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
describedAs
in class ObjectGroupAssert<Collection<?>>
description
- the description of the actual value.
public CollectionAssert satisfies(Condition<Collection<?>> condition)
satisfies
in class GenericAssert<Collection<?>>
condition
- the given condition.
NullPointerException
- if the given condition is null
.
AssertionError
- if the actual collection does not satisfy the given condition.is(Condition)
public CollectionAssert doesNotSatisfy(Condition<Collection<?>> condition)
doesNotSatisfy
in class GenericAssert<Collection<?>>
condition
- the given condition.
NullPointerException
- if the given condition is null
.
AssertionError
- if the actual collection satisfies the given condition.isNot(Condition)
public CollectionAssert is(Condition<Collection<?>> condition)
satisfies(Condition)
.
is
in class GenericAssert<Collection<?>>
condition
- the given condition.
NullPointerException
- if the given condition is null
.
AssertionError
- if the actual collection does not satisfy the given condition.public CollectionAssert isNot(Condition<Collection<?>> condition)
doesNotSatisfy(Condition)
.
isNot
in class GenericAssert<Collection<?>>
condition
- the given condition.
NullPointerException
- if the given condition is null
.
AssertionError
- if the actual collection satisfies the given condition.public CollectionAssert isNotNull()
null
.
isNotNull
in class GenericAssert<Collection<?>>
AssertionError
- if the actual collection is null
.public CollectionAssert isNotEmpty()
isNotEmpty
in class GroupAssert<Collection<?>>
AssertionError
- if the actual collection is null
.
AssertionError
- if the actual collection is empty.public CollectionAssert hasSize(int expected)
hasSize
in class GroupAssert<Collection<?>>
expected
- the expected number of elements in the actual collection.
AssertionError
- if the actual collection is null
.
AssertionError
- if the number of elements of the actual collection is not equal to the given one.protected int actualGroupSize()
actualGroupSize
in class GroupAssert<Collection<?>>
AssertionError
- if the actual collection is null
.public CollectionAssert isEqualTo(Collection<?> expected)
isEqualTo
in class GenericAssert<Collection<?>>
expected
- the given collection to compare the actual collection to.
AssertionError
- if the actual collection is not equal to the given one.public CollectionAssert isNotEqualTo(Collection<?> other)
isNotEqualTo
in class GenericAssert<Collection<?>>
other
- the given collection to compare the actual collection to.
AssertionError
- if the actual collection is equal to the given one.public CollectionAssert isSameAs(Collection<?> expected)
isSameAs
in class GenericAssert<Collection<?>>
expected
- the given collection to compare the actual collection to.
AssertionError
- if the actual collection is not the same as the given one.public CollectionAssert isNotSameAs(Collection<?> other)
isNotSameAs
in class GenericAssert<Collection<?>>
other
- the given collection to compare the actual collection to.
AssertionError
- if the actual collection is the same as the given one.public CollectionAssert overridingErrorMessage(String message)
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'".
overridingErrorMessage
in class ObjectGroupAssert<Collection<?>>
message
- the given error message, which will replace the default one.
public CollectionAssert onProperty(String propertyName)
CollectionAssert
whose target collection contains the values of the
given property name from the elements of this CollectionAssert
's collection. Property access works with
both simple properties like Person.age
and nested properties Person.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
onProperty
in class ObjectGroupAssert<Collection<?>>
propertyName
- the name of the property to extract values from the actual collection to build a new
CollectionAssert
.
CollectionAssert
containing the values of the given property name from the elements of this
CollectionAssert
's collection.
AssertionError
- if the actual collection is null
.
org.fest.util.IntrospectionError
- if an element in the given collection does not have a matching property.protected Set<Object> actualAsSet()
Set
.
actualAsSet
in class ItemGroupAssert<Collection<?>>
Set
.protected List<Object> actualAsList()
List
.
actualAsList
in class ItemGroupAssert<Collection<?>>
List
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |