Package org.fest.assertions
Class GenericAssert<T>
java.lang.Object
org.fest.assertions.Assert
org.fest.assertions.GenericAssert<T>
- Type Parameters:
T- the type of object implementations of this template can verify.
- Direct Known Subclasses:
BooleanAssert,ByteAssert,CharAssert,ComparableAssert,DoubleAssert,FileAssert,FloatAssert,GroupAssert,ImageAssert,IntAssert,LongAssert,ObjectAssert,ShortAssert,ThrowableAssert
Understands a template for assertion methods.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract GenericAssert<T>Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErrorprotected abstract GenericAssert<T>as(Description description) Sets the description of the actual value, to be used in as message of anythrown when an assertion fails.AssertionErrorprotected final voidassertDoesNotSatisfy(Condition<T> condition) Verifies that the actual value does not satisfy the given condition.protected final voidassertEqualTo(T expected) Verifies that the actual value is equal to the given one.protected final voidVerifies that the actual value satisfies the given condition.protected final voidassertIsNot(Condition<T> condition) Verifies that the actual value does not satisfy the given condition.protected final voidassertNotEqualTo(T other) Verifies that the actual value is not equal to the given one.protected final voidVerifies that the actual value is notnull.protected final voidassertNotSameAs(T expected) Verifies that the actual value is not the same as the given one.protected final voidassertSameAs(T expected) Verifies that the actual value is the same as the given one.protected final voidassertSatisfies(Condition<T> condition) Verifies that the actual value satisfies the given condition.protected abstract GenericAssert<T>describedAs(String description) Alias for, since "as" is a keyword in Groovy.as(String)protected abstract GenericAssert<T>describedAs(Description description) Alias for, since "as" is a keyword in Groovy.as(Description)protected abstract GenericAssert<T>doesNotSatisfy(Condition<T> condition) Verifies that the actual value does not satisfy the given condition.private StringerrorMessageIfConditionNotSatisfied(Condition<T> condition) private StringerrorMessageIfConditionSatisfied(Condition<T> condition) private StringerrorMessageIfIs(Condition<T> condition) private StringerrorMessageIfIsNot(Condition<T> condition) protected abstract GenericAssert<T>Alias for.satisfies(Condition)protected abstract GenericAssert<T>Verifies that the actual value is equal to the given one.protected abstract GenericAssert<T>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>Verifies that the actual value is notnull.protected abstract GenericAssert<T>isNotSameAs(T other) Verifies that the actual value is not the same as the given one.final voidisNull()Asserts that the actual value (specified in the constructor of this class) isnull.protected abstract GenericAssert<T>Verifies that the actual value is the same as the given one.private booleanprotected abstract GenericAssert<T>overridingErrorMessage(String message) Replaces the default message displayed in case of a failure with the given one.protected abstract GenericAssert<T>Verifies that the actual value satisfies the given condition.private voidvalidateIsNotNull(Condition<T> condition) Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
-
Field Details
-
actual
-
-
Constructor Details
-
GenericAssert
Creates a new.GenericAssert- Parameters:
actual- the actual target to verify.
-
-
Method Details
-
isNull
public final void isNull()Asserts that the actual value (specified in the constructor of this class) isnull.- Throws:
AssertionError- if the actual value is notnull.
-
satisfies
Verifies that the actual value satisfies the given condition.- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actual value does not satisfy the given condition.- See Also:
-
doesNotSatisfy
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 isnull.AssertionError- if the actual value satisfies the given condition.- See Also:
-
is
Alias for.satisfies(Condition)- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actual value does not satisfy the given condition.- Since:
- 1.2
-
isNot
Alias for.doesNotSatisfy(Condition)- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actual value satisfies the given condition.- Since:
- 1.2
-
as
Sets the description of the actual value, to be used in as message of anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as("name").isEqualTo("Frodo");- 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.as(String)For example:
assertThat(val).describedAs("name").isEqualTo("Frodo");- 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 anythrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.AssertionErrorFor example:
assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");- 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.as(Description)For example:
assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");- Parameters:
description- the description of the actual value.- Returns:
- this assertion object.
-
isEqualTo
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
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
Verifies that the actual value is notnull.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.
-
isSameAs
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
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
Verifies that the actual value satisfies the given condition.- Parameters:
condition- the condition to check.- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actual value does not satisfy the given condition.
-
errorMessageIfConditionNotSatisfied
-
assertIs
Verifies that the actual value satisfies the given condition.- Parameters:
condition- the condition to check.- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actual value does not satisfy the given condition.
-
errorMessageIfIsNot
-
assertDoesNotSatisfy
Verifies that the actual value does not satisfy the given condition.- Parameters:
condition- the condition to check.- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actual value satisfies the given condition.
-
errorMessageIfConditionSatisfied
-
assertIsNot
Verifies that the actual value does not satisfy the given condition.- Parameters:
condition- the condition to check.- Throws:
NullPointerException- if the given condition isnull.AssertionError- if the actual value satisfies the given condition.
-
matches
-
validateIsNotNull
-
errorMessageIfIs
-
assertEqualTo
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
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 notnull.- Throws:
AssertionError- if the actual value isnull.
-
assertSameAs
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
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
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
-