org.fest.assertions
Class GenericAssert<T>

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

public abstract class GenericAssert<T>
extends Assert

Understands a template for assertion methods.

Author:
Yvonne Wang, Alex Ruiz

Field Summary
protected  T actual
           
 
Constructor Summary
protected GenericAssert(T actual)
          Creates a new GenericAssert.
 
Method Summary
protected abstract  GenericAssert<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  GenericAssert<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 assertDoesNotSatisfy(Condition<T> condition)
          Verifies that the actual value does not satisfy the given condition.
protected  void assertEqualTo(T expected)
          Verifies that the actual value is equal to the given one.
protected  void assertIs(Condition<T> condition)
          Verifies that the actual value satisfies the given condition.
protected  void assertIsNot(Condition<T> condition)
          Verifies that the actual value does not satisfy the given condition.
protected  void assertNotEqualTo(T other)
          Verifies that the actual value is not equal to the given one.
protected  void assertNotNull()
          Verifies that the actual value is not null.
protected  void assertNotSameAs(T expected)
          Verifies that the actual value is not the same as the given one.
protected  void assertSameAs(T expected)
          Verifies that the actual value is the same as the given one.
protected  void assertSatisfies(Condition<T> condition)
          Verifies that the actual value satisfies the given condition.
protected abstract  GenericAssert<T> describedAs(Description description)
          Alias for as(Description), since "as" is a keyword in Groovy.
protected abstract  GenericAssert<T> describedAs(String description)
          Alias for as(String), since "as" is a keyword in Groovy.
protected abstract  GenericAssert<T> doesNotSatisfy(Condition<T> condition)
          Verifies that the actual value does not satisfy the given condition.
protected abstract  GenericAssert<T> is(Condition<T> condition)
          Alias for satisfies(Condition).
protected abstract  GenericAssert<T> isEqualTo(T expected)
          Verifies that the actual value is equal to the given one.
protected abstract  GenericAssert<T> isNot(Condition<T> condition)
          Alias for doesNotSatisfy(Condition).
protected abstract  GenericAssert<T> isNotEqualTo(T other)
          Verifies that the actual value is not equal to the given one.
protected abstract  GenericAssert<T> isNotNull()
          Verifies that the actual value is not null.
protected abstract  GenericAssert<T> isNotSameAs(T other)
          Verifies that the actual value is not the same as the given one.
 void isNull()
          Asserts that the actual value (specified in the constructor of this class) is null.
protected abstract  GenericAssert<T> isSameAs(T expected)
          Verifies that the actual value is the same as the given one.
protected abstract  GenericAssert<T> overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
protected abstract  GenericAssert<T> satisfies(Condition<T> condition)
          Verifies that the actual value satisfies the given condition.
 
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
 

Field Detail

actual

protected final T actual
Constructor Detail

GenericAssert

protected GenericAssert(T actual)
Creates a new GenericAssert.

Parameters:
actual - the actual target to verify.
Method Detail

isNull

public final void isNull()
Asserts that the actual value (specified in the constructor of this class) is null.

Throws:
AssertionError - if the actual value is not null.

satisfies

protected abstract GenericAssert<T> satisfies(Condition<T> condition)
Verifies that the actual value satisfies the given condition.

Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value does not satisfy the given condition.
See Also:
is(Condition)

doesNotSatisfy

protected abstract GenericAssert<T> doesNotSatisfy(Condition<T> condition)
Verifies that the actual value does not satisfy the given condition.

Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value does satisfies the given condition.
See Also:
isNot(Condition)

is

protected abstract GenericAssert<T> is(Condition<T> condition)
Alias for satisfies(Condition).

Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value does not satisfy the given condition.
Since:
1.2

isNot

protected abstract GenericAssert<T> isNot(Condition<T> condition)
Alias for doesNotSatisfy(Condition).

Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value does satisfies the given condition.
Since:
1.2

as

protected abstract GenericAssert<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");
 

Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

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

Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

protected abstract GenericAssert<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");
 

Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

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

Parameters:
description - the description of the actual value.
Returns:
this assertion object.

isEqualTo

protected abstract GenericAssert<T> isEqualTo(T expected)
Verifies that the actual value is equal to the given one.

Parameters:
expected - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is not equal to the given one.

isNotEqualTo

protected abstract GenericAssert<T> isNotEqualTo(T other)
Verifies that the actual value is not equal to the given one.

Parameters:
other - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is equal to the given one.

isNotNull

protected abstract GenericAssert<T> isNotNull()
Verifies that the actual value is not null.

Returns:
this assertion object.
Throws:
AssertionError - if the actual value is null.

isSameAs

protected abstract GenericAssert<T> isSameAs(T expected)
Verifies that the actual value is the same as the given one.

Parameters:
expected - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is not the same as the given one.

isNotSameAs

protected abstract GenericAssert<T> isNotSameAs(T other)
Verifies that the actual value is not the same as the given one.

Parameters:
other - the given value to compare the actual value to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual value is the same as the given one.

assertSatisfies

protected final void assertSatisfies(Condition<T> condition)
Verifies that the actual value satisfies the given condition.

Parameters:
condition - the condition to check.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value does not satisfy the given condition.

assertIs

protected final void assertIs(Condition<T> condition)
Verifies that the actual value satisfies the given condition.

Parameters:
condition - the condition to check.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value does not satisfy the given condition.

assertDoesNotSatisfy

protected final void assertDoesNotSatisfy(Condition<T> condition)
Verifies that the actual value does not satisfy the given condition.

Parameters:
condition - the condition to check.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value satisfies the given condition.

assertIsNot

protected final void assertIsNot(Condition<T> condition)
Verifies that the actual value does not satisfy the given condition.

Parameters:
condition - the condition to check.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual value satisfies the given condition.

assertEqualTo

protected final void assertEqualTo(T expected)
Verifies that the actual value is equal to the given one.

Parameters:
expected - the value to compare the actual value to.
Throws:
AssertionError - if the actual value is not equal to the given one.

assertNotEqualTo

protected final void assertNotEqualTo(T other)
Verifies that the actual value is not equal to the given one.

Parameters:
other - the value to compare the actual value to.
Throws:
AssertionError - if the actual value is equal to the given one.

assertNotNull

protected final void assertNotNull()
Verifies that the actual value is not null.

Throws:
AssertionError - if the actual value is null.

assertSameAs

protected final void assertSameAs(T expected)
Verifies that the actual value is the same as the given one.

Parameters:
expected - the value to compare the actual value to.
Throws:
AssertionError - if the actual value is not the same as the given one.

assertNotSameAs

protected final void assertNotSameAs(T expected)
Verifies that the actual value is not the same as the given one.

Parameters:
expected - the value to compare the actual value to.
Throws:
AssertionError - if the actual value is the same as the given one.

overridingErrorMessage

protected abstract GenericAssert<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'".

Parameters:
message - the given error message, which will replace the default one.
Returns:
this assertion.
Since:
1.2


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