Class AbstractAssert<S extends AbstractAssert<S,A>,A>
- Type Parameters:
S
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.A
- the type of the "actual" value.
- All Implemented Interfaces:
Assert<S,
,A> Descriptable<S>
,ExtensionPoints<S,
A>
- Direct Known Subclasses:
AbstractComparableAssert
,AbstractIterableAssert
,BooleanArrayAssert
,BooleanAssert
,ByteArrayAssert
,CharArrayAssert
,DateAssert
,DoubleArrayAssert
,FileAssert
,FloatArrayAssert
,InputStreamAssert
,IntArrayAssert
,LongArrayAssert
,MapAssert
,ObjectArrayAssert
,ObjectAssert
,ShortArrayAssert
,StringAssert
,ThrowableAssert
- Author:
- Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Nicolas François
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the description of this object.as
(Description description) Sets the description of this object.describedAs
(String description) Alias for
since "as" is a keyword in Groovy.Descriptable.as(String)
describedAs
(Description description) Alias for
since "as" is a keyword in Groovy.Descriptable.as(String)
The description of this assertion set withdescribedAs(String)
ordescribedAs(Description)
.doesNotHave
(Condition<? super A> condition) Verifies that the actual value does not satisfy the given condition.doesNotHaveSameClassAs
(Object other) Verifies that the actual value does not have the same class as the given object.final boolean
Throws
if called.UnsupportedOperationException
protected WritableAssertionInfo
Exposes theWritableAssertionInfo
used in the current assertion for better extensibility. When writing your own assertion class, you can use the returnedWritableAssertionInfo
to change the error message and still keep the description set by the assertion user.Verifies that the actual value satisfies the given condition.final int
hashCode()
Always returns 1.hasSameClassAs
(Object other) Verifies that the actual value has the same class as the given object.Verifies that the actual value satisfies the given condition.Verifies that the actual value is equal to the given one.isExactlyInstanceOf
(Class<?> type) Verifies that the actual value is exactly an instance of the given type.Verifies that the actual value is present in the given array of values.Verifies that the actual value is present in the given values.isInstanceOf
(Class<?> type) Verifies that the actual value is an instance of the given type.isInstanceOfAny
(Class<?>... types) Verifies that the actual value is an instance of any of the given types.Verifies that the actual value does not satisfy the given condition.isNotEqualTo
(A other) Verifies that the actual value is not equal to the given one.isNotExactlyInstanceOf
(Class<?> type) Verifies that the actual value is not exactly an instance of given type.Verifies that the actual value is not present in the given array of values.Verifies that the actual value is not present in the given values.isNotInstanceOf
(Class<?> type) Verifies that the actual value is not an instance of the given type.isNotInstanceOfAny
(Class<?>... types) Verifies that the actual value is not an instance of any of the given types.Verifies that the actual value is notnull
.isNotOfAnyClassIn
(Class<?>... types) Verifies that the actual value type is not in given types.isNotSameAs
(A other) Verifies that the actual value is not the same as the given one.void
isNull()
Verifies that the actual value isnull
.isOfAnyClassIn
(Class<?>... types) Verifies that the actual value type is in given types.Verifies that the actual value is the same as the given one.overridingErrorMessage
(String newErrorMessage, Object... args) Overrides Fest default error message by the given one, the new error message can be built usingString.format(String, Object...)
, hence the presence of args parameter.usingComparator
(Comparator<? super A> customComparator) Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Revert to standard comparison for incoming assertion checks.
-
Field Details
-
actual
-
myself
-
-
Constructor Details
-
AbstractAssert
-
-
Method Details
-
getWritableAssertionInfo
Exposes theWritableAssertionInfo
used in the current assertion for better extensibility. When writing your own assertion class, you can use the returnedWritableAssertionInfo
to change the error message and still keep the description set by the assertion user.- Returns:
- the
WritableAssertionInfo
used in the current assertion
-
as
Sets the description of this object.- Specified by:
as
in interfaceDescriptable<S extends AbstractAssert<S,
A>> - Parameters:
description
- the new description to set.- Returns:
this
object.- See Also:
-
as
Sets the description of this object. To remove or clear the description, pass a
as argument.EmptyTextDescription
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
as
in interfaceDescriptable<S extends AbstractAssert<S,
A>> - Parameters:
description
- the new description to set.- Returns:
this
object.- See Also:
-
describedAs
Alias for
since "as" is a keyword in Groovy.Descriptable.as(String)
- Specified by:
describedAs
in interfaceDescriptable<S extends AbstractAssert<S,
A>> - Parameters:
description
- the new description to set.- Returns:
this
object.
-
describedAs
Alias for
since "as" is a keyword in Groovy. To remove or clear the description, pass aDescriptable.as(String)
as argument.EmptyTextDescription
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
describedAs
in interfaceDescriptable<S extends AbstractAssert<S,
A>> - Parameters:
description
- the new description to set.- Returns:
this
object.
-
isEqualTo
Verifies that the actual value is equal to the given one. -
isNotEqualTo
Verifies that the actual value is not equal to the given one.- Specified by:
isNotEqualTo
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
other
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isNull
public void isNull()Verifies that the actual value isnull
. -
isNotNull
Verifies that the actual value is notnull
. -
isSameAs
Verifies that the actual value is the same as the given one. -
isNotSameAs
Verifies that the actual value is not the same as the given one.- Specified by:
isNotSameAs
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
other
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isIn
Verifies that the actual value is present in the given array of values. -
isNotIn
Verifies that the actual value is not present in the given array of values. -
isIn
Verifies that the actual value is present in the given values. -
isNotIn
Verifies that the actual value is not present in the given values. -
is
Verifies that the actual value satisfies the given condition. This method is an alias for
.ExtensionPoints.has(Condition)
- Specified by:
is
in interfaceExtensionPoints<S extends AbstractAssert<S,
A>, A> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
isNot
Verifies that the actual value does not satisfy the given condition. This method is an alias for
.ExtensionPoints.doesNotHave(Condition)
- Specified by:
isNot
in interfaceExtensionPoints<S extends AbstractAssert<S,
A>, A> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
has
Verifies that the actual value satisfies the given condition. This method is an alias for
.ExtensionPoints.is(Condition)
- Specified by:
has
in interfaceExtensionPoints<S extends AbstractAssert<S,
A>, A> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
doesNotHave
Verifies that the actual value does not satisfy the given condition. This method is an alias for
.ExtensionPoints.isNot(Condition)
- Specified by:
doesNotHave
in interfaceExtensionPoints<S extends AbstractAssert<S,
A>, A> - Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
-
isInstanceOf
Verifies that the actual value is an instance of the given type.- Specified by:
isInstanceOf
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isInstanceOfAny
Verifies that the actual value is an instance of any of the given types.- Specified by:
isInstanceOfAny
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotInstanceOf
Verifies that the actual value is not an instance of the given type.- Specified by:
isNotInstanceOf
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotInstanceOfAny
Verifies that the actual value is not an instance of any of the given types.- Specified by:
isNotInstanceOfAny
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
hasSameClassAs
Verifies that the actual value has the same class as the given object.- Specified by:
hasSameClassAs
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
other
- the object to check type against.- Returns:
- this assertion object.
-
doesNotHaveSameClassAs
Verifies that the actual value does not have the same class as the given object.- Specified by:
doesNotHaveSameClassAs
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
other
- the object to check type against.- Returns:
- this assertion object.
-
isExactlyInstanceOf
Verifies that the actual value is exactly an instance of the given type.- Specified by:
isExactlyInstanceOf
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotExactlyInstanceOf
Verifies that the actual value is not exactly an instance of given type.- Specified by:
isNotExactlyInstanceOf
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isOfAnyClassIn
Verifies that the actual value type is in given types.- Specified by:
isOfAnyClassIn
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotOfAnyClassIn
Verifies that the actual value type is not in given types.- Specified by:
isNotOfAnyClassIn
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
descriptionText
The description of this assertion set withdescribedAs(String)
ordescribedAs(Description)
.- Returns:
- the description String representation of this assertion.
-
overridingErrorMessage
Overrides Fest default error message by the given one, the new error message can be built usingString.format(String, Object...)
, hence the presence of args parameter.Example :
assertThat(player.isRookie()).overridingErrorMessage("Expecting Player <%s> to be a rookie but was not.", player) .isTrue();
- Parameters:
newErrorMessage
- the error message that will replace the default one provided by Fest.args
- the args used to fill error message as inString.format(String, Object...)
.- Returns:
- this assertion object.
- Throws:
exception
- seeString.format(String, Object...)
exception clause.
-
usingComparator
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
- Specified by:
usingComparator
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultComparator
Revert to standard comparison for incoming assertion checks.This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.- Specified by:
usingDefaultComparator
in interfaceAssert<S extends AbstractAssert<S,
A>, A> - Returns:
this
assertion object.
-
equals
Throws
if called. It is easy to accidentally callUnsupportedOperationException
instead ofAssert.equals(Object)
isEqualTo
. -
hashCode
public final int hashCode()Always returns 1.
-