S
- used to simulate "self types." For more information please read "Emulating 'self types' using Java Generics to simplify fluent API implementation."A
- the type the "actual" value.public abstract class GenericAssert<S,A> extends Assert
Modifier | Constructor and Description |
---|---|
protected |
GenericAssert(Class<S> selfType,
A actual)
Creates a new
. |
Modifier and Type | Method and Description |
---|---|
S |
as(Description description)
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. |
S |
as(String description)
Sets the description of the actual value, to be used in as message of any
thrown when an assertion fails. |
S |
describedAs(Description description)
Alias for
, since "as" is a keyword in
Groovy. |
S |
describedAs(String description)
Alias for
, since "as" is a keyword in
Groovy. |
S |
doesNotSatisfy(Condition<A> condition)
Verifies that the actual value does not satisfy the given condition.
|
S |
is(Condition<A> condition)
Alias for
. |
S |
isEqualTo(A expected)
Verifies that the actual value is equal to the given one.
|
S |
isIn(Collection<?> values)
Verifies that the actual value is in the given collection.
|
S |
isIn(Object... values)
Verifies that the actual value is in the given values.
|
S |
isNot(Condition<A> condition)
Alias for
. |
S |
isNotEqualTo(A other)
Verifies that the actual value is not equal to the given one.
|
S |
isNotIn(Collection<?> values)
Verifies that the actual value is in the given collection.
|
S |
isNotIn(Object... values)
Verifies that the actual value is in the given values.
|
S |
isNotNull()
Verifies that the actual value is not
null . |
S |
isNotSameAs(A 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 . |
S |
isSameAs(A expected)
Verifies that the actual value is the same as the given one.
|
S |
overridingErrorMessage(String message)
Replaces the default message displayed in case of a failure with the given one.
|
S |
satisfies(Condition<A> condition)
Verifies that the actual value satisfies the given condition.
|
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
protected GenericAssert(Class<S> selfType, A actual)
GenericAssert
.selfType
- the "self type."actual
- the actual value to verify.public final void isNull()
null
.AssertionError
- if the actual value is not null
.public final S satisfies(Condition<A> condition)
condition
- the given condition.NullPointerException
- if the given condition is null
.AssertionError
- if the actual value does not satisfy the given condition.is(Condition)
public final S doesNotSatisfy(Condition<A> condition)
condition
- the given condition.NullPointerException
- if the given condition is null
.AssertionError
- if the actual value satisfies the given condition.isNot(Condition)
public final S is(Condition<A> condition)
satisfies(Condition)
.condition
- the given condition.NullPointerException
- if the given condition is null
.AssertionError
- if the actual value does not satisfy the given condition.public final S isNot(Condition<A> condition)
doesNotSatisfy(Condition)
.condition
- the given condition.NullPointerException
- if the given condition is null
.AssertionError
- if the actual value satisfies the given condition.public S 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");
description
- the description of the actual value.public S describedAs(String description)
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");
description
- the description of the actual value.public S 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");
description
- the description of the actual value.public S describedAs(Description description)
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");
description
- the description of the actual value.public S isEqualTo(A expected)
expected
- the given value to compare the actual value to.AssertionError
- if the actual value is not equal to the given one.public S isNotEqualTo(A other)
other
- the given value to compare the actual value to.AssertionError
- if the actual value is equal to the given one.public final S isNotNull()
null
.AssertionError
- if the actual value is null
.public final S isSameAs(A expected)
expected
- the given value to compare the actual value to.AssertionError
- if the actual value is not the same as the given one.public final S isNotSameAs(A other)
other
- the given value to compare the actual value to.AssertionError
- if the actual value is the same as the given one.public final S isIn(Object... values)
values
- the given values to search the actual value in.AssertionError
- if the actual value is not in the given values.NullPointerException
- if the given parameter is null.public final S isIn(Collection<?> values)
values
- the given collection to search the actual value in. must not be null.AssertionError
- if the actual value is not in the given collection.NullPointerException
- if the given collection is null.public final S isNotIn(Object... values)
values
- the given values to search the actual value in.AssertionError
- if the actual value is not in the given values.NullPointerException
- if the given parameter is null.public final S isNotIn(Collection<?> values)
values
- the given collection to search the actual value in. must not be null.AssertionError
- if the actual value is not in the given collection.NullPointerException
- if the given collection is null.public S 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'".
message
- the given error message, which will replace the default one.Copyright © 2007-2013 FEST (Fixtures for Easy Software Testing). All Rights Reserved.