Class AbstractAssert<S extends AbstractAssert<S,A>,A>
- java.lang.Object
-
- org.fest.assertions.api.AbstractAssert<S,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
public abstract class AbstractAssert<S extends AbstractAssert<S,A>,A> extends java.lang.Object implements Assert<S,A>
Base class for all assertions.- Author:
- Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Nicolas François
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractAssert(A actual, java.lang.Class<?> selfType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Sas(java.lang.String description)Sets the description of this object.Sas(Description description)Sets the description of this object.SdescribedAs(java.lang.String description)Alias forsince "as" is a keyword in Groovy.Descriptable.as(String)SdescribedAs(Description description)Alias forsince "as" is a keyword in Groovy.Descriptable.as(String)java.lang.StringdescriptionText()The description of this assertion set withdescribedAs(String)ordescribedAs(Description).SdoesNotHave(Condition<? super A> condition)Verifies that the actual value does not satisfy the given condition.SdoesNotHaveSameClassAs(java.lang.Object other)Verifies that the actual value does not have the same class as the given object.booleanequals(java.lang.Object obj)Throwsif called.UnsupportedOperationExceptionprotected WritableAssertionInfogetWritableAssertionInfo()Exposes theWritableAssertionInfoused in the current assertion for better extensibility. When writing your own assertion class, you can use the returnedWritableAssertionInfoto change the error message and still keep the description set by the assertion user.Shas(Condition<? super A> condition)Verifies that the actual value satisfies the given condition.inthashCode()Always returns 1.ShasSameClassAs(java.lang.Object other)Verifies that the actual value has the same class as the given object.Sis(Condition<? super A> condition)Verifies that the actual value satisfies the given condition.SisEqualTo(A expected)Verifies that the actual value is equal to the given one.SisExactlyInstanceOf(java.lang.Class<?> type)Verifies that the actual value is exactly an instance of the given type.SisIn(A... values)Verifies that the actual value is present in the given array of values.SisIn(java.lang.Iterable<? extends A> values)Verifies that the actual value is present in the given values.SisInstanceOf(java.lang.Class<?> type)Verifies that the actual value is an instance of the given type.SisInstanceOfAny(java.lang.Class<?>... types)Verifies that the actual value is an instance of any of the given types.SisNot(Condition<? super A> condition)Verifies that the actual value does not satisfy the given condition.SisNotEqualTo(A other)Verifies that the actual value is not equal to the given one.SisNotExactlyInstanceOf(java.lang.Class<?> type)Verifies that the actual value is not exactly an instance of given type.SisNotIn(A... values)Verifies that the actual value is not present in the given array of values.SisNotIn(java.lang.Iterable<? extends A> values)Verifies that the actual value is not present in the given values.SisNotInstanceOf(java.lang.Class<?> type)Verifies that the actual value is not an instance of the given type.SisNotInstanceOfAny(java.lang.Class<?>... types)Verifies that the actual value is not an instance of any of the given types.SisNotNull()Verifies that the actual value is notnull.SisNotOfAnyClassIn(java.lang.Class<?>... types)Verifies that the actual value type is not in given types.SisNotSameAs(A other)Verifies that the actual value is not the same as the given one.voidisNull()Verifies that the actual value isnull.SisOfAnyClassIn(java.lang.Class<?>... types)Verifies that the actual value type is in given types.SisSameAs(A expected)Verifies that the actual value is the same as the given one.SoverridingErrorMessage(java.lang.String newErrorMessage, java.lang.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.SusingComparator(java.util.Comparator<? super A> customComparator)Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.SusingDefaultComparator()Revert to standard comparison for incoming assertion checks.
-
-
-
Field Detail
-
actual
protected final A actual
-
myself
protected final S extends AbstractAssert<S,A> myself
-
-
Constructor Detail
-
AbstractAssert
protected AbstractAssert(A actual, java.lang.Class<?> selfType)
-
-
Method Detail
-
getWritableAssertionInfo
protected WritableAssertionInfo getWritableAssertionInfo()
Exposes theWritableAssertionInfoused in the current assertion for better extensibility. When writing your own assertion class, you can use the returnedWritableAssertionInfoto change the error message and still keep the description set by the assertion user.- Returns:
- the
WritableAssertionInfoused in the current assertion
-
as
public S as(java.lang.String description)
Sets the description of this object.- Specified by:
asin interfaceDescriptable<S extends AbstractAssert<S,A>>- Parameters:
description- the new description to set.- Returns:
thisobject.- See Also:
Descriptable.describedAs(String)
-
as
public S as(Description description)
Sets the description of this object. To remove or clear the description, pass aas argument.EmptyTextDescriptionThis overloaded version of "describedAs" offers more flexibility than the one taking a
Stringby 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:
asin interfaceDescriptable<S extends AbstractAssert<S,A>>- Parameters:
description- the new description to set.- Returns:
thisobject.- See Also:
Descriptable.describedAs(Description)
-
describedAs
public S describedAs(java.lang.String description)
Alias forsince "as" is a keyword in Groovy.Descriptable.as(String)- Specified by:
describedAsin interfaceDescriptable<S extends AbstractAssert<S,A>>- Parameters:
description- the new description to set.- Returns:
thisobject.
-
describedAs
public S describedAs(Description description)
Alias forsince "as" is a keyword in Groovy. To remove or clear the description, pass aDescriptable.as(String)as argument.EmptyTextDescriptionThis overloaded version of "describedAs" offers more flexibility than the one taking a
Stringby 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:
describedAsin interfaceDescriptable<S extends AbstractAssert<S,A>>- Parameters:
description- the new description to set.- Returns:
thisobject.
-
isNotEqualTo
public S isNotEqualTo(A other)
Verifies that the actual value is not equal to the given one.- Specified by:
isNotEqualToin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isNull
public void isNull()
Verifies that the actual value isnull.
-
isNotNull
public S isNotNull()
Verifies that the actual value is notnull.
-
isSameAs
public S isSameAs(A expected)
Verifies that the actual value is the same as the given one.
-
isNotSameAs
public S isNotSameAs(A other)
Verifies that the actual value is not the same as the given one.- Specified by:
isNotSameAsin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isIn
public S isIn(A... values)
Verifies that the actual value is present in the given array of values.
-
isNotIn
public S isNotIn(A... values)
Verifies that the actual value is not present in the given array of values.
-
isIn
public S isIn(java.lang.Iterable<? extends A> values)
Verifies that the actual value is present in the given values.
-
isNotIn
public S isNotIn(java.lang.Iterable<? extends A> values)
Verifies that the actual value is not present in the given values.
-
is
public S is(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition. This method is an alias for.ExtensionPoints.has(Condition)- Specified by:
isin interfaceExtensionPoints<S extends AbstractAssert<S,A>,A>- Parameters:
condition- the given condition.- Returns:
this ExtensionPointsobject.- See Also:
ExtensionPoints.is(Condition)
-
isNot
public S isNot(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition. This method is an alias for.ExtensionPoints.doesNotHave(Condition)- Specified by:
isNotin interfaceExtensionPoints<S extends AbstractAssert<S,A>,A>- Parameters:
condition- the given condition.- Returns:
this ExtensionPointsobject.- See Also:
ExtensionPoints.isNot(Condition)
-
has
public S has(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition. This method is an alias for.ExtensionPoints.is(Condition)- Specified by:
hasin interfaceExtensionPoints<S extends AbstractAssert<S,A>,A>- Parameters:
condition- the given condition.- Returns:
this ExtensionPointsobject.- See Also:
ExtensionPoints.is(Condition)
-
doesNotHave
public S doesNotHave(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition. This method is an alias for.ExtensionPoints.isNot(Condition)- Specified by:
doesNotHavein interfaceExtensionPoints<S extends AbstractAssert<S,A>,A>- Parameters:
condition- the given condition.- Returns:
this ExtensionPointsobject.- See Also:
ExtensionPoints.isNot(Condition)
-
isInstanceOf
public S isInstanceOf(java.lang.Class<?> type)
Verifies that the actual value is an instance of the given type.- Specified by:
isInstanceOfin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
type- the type to check the actual value against.- Returns:
- this assertion object.
-
isInstanceOfAny
public S isInstanceOfAny(java.lang.Class<?>... types)
Verifies that the actual value is an instance of any of the given types.- Specified by:
isInstanceOfAnyin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
types- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotInstanceOf
public S isNotInstanceOf(java.lang.Class<?> type)
Verifies that the actual value is not an instance of the given type.- Specified by:
isNotInstanceOfin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
type- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotInstanceOfAny
public S isNotInstanceOfAny(java.lang.Class<?>... types)
Verifies that the actual value is not an instance of any of the given types.- Specified by:
isNotInstanceOfAnyin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
types- the types to check the actual value against.- Returns:
- this assertion object.
-
hasSameClassAs
public S hasSameClassAs(java.lang.Object other)
Verifies that the actual value has the same class as the given object.- Specified by:
hasSameClassAsin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
other- the object to check type against.- Returns:
- this assertion object.
-
doesNotHaveSameClassAs
public S doesNotHaveSameClassAs(java.lang.Object other)
Verifies that the actual value does not have the same class as the given object.- Specified by:
doesNotHaveSameClassAsin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
other- the object to check type against.- Returns:
- this assertion object.
-
isExactlyInstanceOf
public S isExactlyInstanceOf(java.lang.Class<?> type)
Verifies that the actual value is exactly an instance of the given type.- Specified by:
isExactlyInstanceOfin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
type- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotExactlyInstanceOf
public S isNotExactlyInstanceOf(java.lang.Class<?> type)
Verifies that the actual value is not exactly an instance of given type.- Specified by:
isNotExactlyInstanceOfin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
type- the type to check the actual value against.- Returns:
- this assertion object.
-
isOfAnyClassIn
public S isOfAnyClassIn(java.lang.Class<?>... types)
Verifies that the actual value type is in given types.- Specified by:
isOfAnyClassInin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
types- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotOfAnyClassIn
public S isNotOfAnyClassIn(java.lang.Class<?>... types)
Verifies that the actual value type is not in given types.- Specified by:
isNotOfAnyClassInin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
types- the types to check the actual value against.- Returns:
- this assertion object.
-
descriptionText
public java.lang.String descriptionText()
The description of this assertion set withdescribedAs(String)ordescribedAs(Description).- Returns:
- the description String representation of this assertion.
-
overridingErrorMessage
public S overridingErrorMessage(java.lang.String newErrorMessage, java.lang.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.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
public S usingComparator(java.util.Comparator<? super A> customComparator)
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:
usingComparatorin interfaceAssert<S extends AbstractAssert<S,A>,A>- Parameters:
customComparator- the comparator to use for incoming assertion checks.- Returns:
thisassertion object.
-
usingDefaultComparator
public S 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:
usingDefaultComparatorin interfaceAssert<S extends AbstractAssert<S,A>,A>- Returns:
thisassertion object.
-
equals
public final boolean equals(java.lang.Object obj)
Throwsif called. It is easy to accidentally callUnsupportedOperationExceptioninstead ofAssert.equals(Object)isEqualTo.
-
hashCode
public final int hashCode()
Always returns 1.- Overrides:
hashCodein classjava.lang.Object- Returns:
- 1.
-
-