org.fest.assertions
Class GroupAssert<T>

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<T>
          extended by org.fest.assertions.GroupAssert<T>
Type Parameters:
T - the type of object implementations of this template can verify.
Direct Known Subclasses:
ItemGroupAssert, MapAssert, StringAssert

public abstract class GroupAssert<T>
extends GenericAssert<T>

Understands a template for assertion methods related to classes representing groups of values.

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual
 
Constructor Summary
protected GroupAssert(T actual)
          Creates a new GroupAssert.
 
Method Summary
protected abstract  int actualGroupSize()
          Returns the size of the actual group of values (array, collection, etc.)
protected abstract  GroupAssert<T> as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
protected abstract  GroupAssert<T> as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
protected  void assertHasSize(int expected)
          Verifies that the number of elements in the actual group of values is equal to the given one.
protected  void assertIsNotEmpty()
          Verifies that the actual group of values contains at least one element.
protected abstract  GroupAssert<T> describedAs(Description description)
          Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy.
protected abstract  GroupAssert<T> describedAs(String description)
          Alias for GenericAssert.as(String), since "as" is a keyword in Groovy.
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> isNotEmpty()
          Verifies that the actual group contains at least on value.
 void isNullOrEmpty()
          Verifies that the actual group of values is null 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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupAssert

protected GroupAssert(T actual)
Creates a new GroupAssert.

Parameters:
actual - the target to verify.
Method Detail

isNullOrEmpty

public void isNullOrEmpty()
Verifies that the actual group of values is null or empty.

Throws:
AssertionError - if the actual group of values is not null or not empty.

isEmpty

public void isEmpty()
Verifies that the actual group of values is empty.

Throws:
AssertionError - if the actual group of values is null or not empty.

isNotEmpty

protected abstract GroupAssert<T> isNotEmpty()
Verifies that the actual group contains at least on value.

Returns:
this assertion object.
Throws:
AssertionError - if the actual group is null 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 is null.
AssertionError - if the actual group of values is empty.

hasSize

protected abstract GroupAssert<T> hasSize(int expected)
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 is null.
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

protected abstract GroupAssert<T> as(String description)
Sets the description of the actual value, to be used in as message of any 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");
 

Specified by:
as in class GenericAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

protected abstract GroupAssert<T> describedAs(String description)
Alias for 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");
 

Specified by:
describedAs in class GenericAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

protected abstract GroupAssert<T> as(Description description)
Sets the description of the actual value, to be used in as message of any 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");
 

Specified by:
as in class GenericAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

protected abstract GroupAssert<T> describedAs(Description description)
Alias for 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");
 

Specified by:
describedAs in class GenericAssert<T>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

overridingErrorMessage

protected abstract GroupAssert<T> overridingErrorMessage(String message)
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 class GenericAssert<T>
Parameters:
message - the given error message, which will replace the default one.
Returns:
this assertion.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.