Top Description Fields Constructors Methods
org.assertj.core.api

public abstract Class AbstractAssert<SELF extends AbstractAssert<SELF, ACTUAL>, ACTUAL>

extends Object
implements Assert<SELF extends AbstractAssert<SELF, ACTUAL>, ACTUAL>
Class Inheritance
All Implemented Interfaces
org.assertj.core.api.Assert, org.assertj.core.api.ExtensionPoints, org.assertj.core.api.Descriptable
Known Direct Subclasses
org.assertj.core.api.AbstractBooleanAssert, org.assertj.core.api.AbstractCharSequenceAssert, org.assertj.core.api.AbstractClassAssert, org.assertj.core.api.AbstractCompletableFutureAssert, org.assertj.core.api.AbstractDateAssert, org.assertj.core.api.AbstractEnumerableAssert, org.assertj.core.api.AtomicBooleanAssert, org.assertj.core.api.AtomicIntegerAssert, org.assertj.core.api.AtomicLongAssert, org.assertj.core.api.RecursiveAssertionAssert, org.assertj.core.api.RecursiveComparisonAssert, org.assertj.core.api.AbstractFileAssert, org.assertj.core.api.AbstractMatcherAssert, org.assertj.core.api.AbstractObjectArrayAssert, org.assertj.core.api.AbstractObjectAssert, org.assertj.core.api.AbstractOptionalAssert, org.assertj.core.api.AbstractOptionalDoubleAssert, org.assertj.core.api.AbstractOptionalIntAssert, org.assertj.core.api.AbstractOptionalLongAssert, org.assertj.core.api.AbstractPeriodAssert, org.assertj.core.api.AbstractPredicateAssert, org.assertj.core.api.AbstractPredicateLikeAssert, org.assertj.core.api.AbstractFutureAssert, org.assertj.core.api.AbstractInputStreamAssert, org.assertj.core.api.AbstractIterableAssert, org.assertj.core.api.AbstractIteratorAssert, org.assertj.core.api.AbstractLongAdderAssert, org.assertj.core.api.AbstractSpliteratorAssert, org.assertj.core.api.AbstractTemporalAssert, org.assertj.core.api.AbstractUrlAssert, org.assertj.core.api.AtomicReferenceArrayAssert, org.assertj.core.api.AtomicReferenceAssert, org.assertj.core.api.Abstract2DArrayAssert
Type Parameters
<SELF>
the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
<ACTUAL>
the type of the "actual" value.
Static Imports
java.lang.String.format, java.util.Arrays.stream, .Objects.requireNonNull, java.util.stream.Collectors.toList, org.assertj.core.description.Description.mostRelevantDescription, org.assertj.core.error.ShouldMatch.shouldMatch, .ShouldNotBeNull.shouldNotBeNull, org.assertj.core.extractor.Extractors.byName, .Extractors.extractedDescriptionOf, org.assertj.core.util.Lists.list, .Preconditions.checkArgument, .Strings.formatIfArgs

Base class for all assertions.
Authors
Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Nicolas François

Field Summary

Modifier and TypeField and Description
protected final ACTUAL
pack-priv AssertionErrorCreator
pack-priv Conditions
pack-priv static Representation
private static Consumer<Description>
public WritableAssertionInfo
protected final SELF
protected Objects
private static final String
pack-priv static boolean
public static boolean

Constructor Summary

AccessConstructor and Description
protected
AbstractAssert(ACTUAL actual, Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

true if actual and other are equal according to the underlying comparison strategy.
areEqual
(Object
the object to compare to other
actual
,
Object
the object to compare to actual
other
)

Deprecated ComparisonStrategy will become part of the public API in the next major release and this method will be removed.
Returns true if actual and other are equal according to the current comparison strategy.
public <ASSERT extends AbstractAssert<?, ?>> ASSERT
asInstanceOf(InstanceOfAssertFactory<?, ASSERT>
the factory which verifies the type and creates the new Assert.
instanceOfAssertFactory
)

Implements org.assertj.core.api.Assert.asInstanceOf.

Uses an InstanceOfAssertFactory to verify that the actual value is an instance of a given type and to produce a new Assert narrowed to that type.
public AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>>
asList()

Implements org.assertj.core.api.Assert.asList.

Verifies that the actual value is an instance of List, and returns a list assertion, to allow chaining of list-specific assertions from this call.
protected AssertionError
assertionError(ErrorMessageFactory errorMessageFactory)

public AbstractStringAssert<?>
asString()

Implements org.assertj.core.api.Assert.asString.

Returns a String assertion for the toString() of the actual value, to allow chaining of String-specific assertions from this call.
private AssertionError
catchAssertionError(Consumer<? super ACTUAL> assertions)

private Optional<AssertionError>
catchOptionalAssertionError(Consumer<? super ACTUAL> assertions)

public SELF
describedAs(Description
the new description to set.
description
)

Implements org.assertj.core.api.Descriptable.describedAs.

Sets the description of the assertion that is going to be called after.
public String

Returns:

the description String representation of this assertion.
descriptionText
()

The description of this assertion set with describedAs(String, Object...) or describedAs(Description).

public SELF
doesNotHave(Condition<? super ACTUAL>
the given condition.
condition
)

Implements org.assertj.core.api.ExtensionPoints.doesNotHave.

Verifies that the actual value does not satisfy the given condition.
public SELF
doesNotHaveSameClassAs(Object
the object to check type against.
other
)

Implements org.assertj.core.api.Assert.doesNotHaveSameClassAs.

Verifies that the actual value does not have the same class as the given object.
public SELF
doesNotHaveSameHashCodeAs(Object
the object to check hashCode against.
other
)

Implements org.assertj.core.api.Assert.doesNotHaveSameHashCodeAs.

Verifies that the actual object does not have the same hashCode as the given object.
public SELF
doesNotHaveToString(String
the String to check against.
otherToString
)

Implements org.assertj.core.api.Assert.doesNotHaveToString.

Verifies that actual actual.toString() is not equal to the given String.
public SELF
doesNotHaveToString(String
the format string to use.
expectedStringTemplate
,
Object...
the arguments to interpolate into the format string.
args
)

Implements org.assertj.core.api.Assert.doesNotHaveToString.

Verifies that actual actual.toString() is not equal to the given String.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Implements org.assertj.core.api.Assert.equals.

Deprecated use isEqualTo instead
Indicates whether some other object is "equal to" this one.
protected <
the type of the resulting Assert
ASSERT extends AbstractAssert<?, ?>
>
ASSERT

Returns:

the new Assert instance
extracting
(String
the property/field to extract from the initial object under test
propertyOrField
,
AssertFactory<Object, ASSERT>
the factory for the creation of the new Assert
assertFactory
)

Extracts the value of given field/property from the object under test and creates a new assertion object using the given assert factory.

protected <
the expected extracted value type
T
,
the type of the resulting Assert
ASSERT extends AbstractAssert<?, ?>
>
ASSERT

Returns:

the new Assert instance
extracting
(Function<? super ACTUAL, ? extends T>
the extractor function used to extract the value from the object under test
extractor
,
AssertFactory<T, ASSERT>
the factory for the creation of the new Assert
assertFactory
)

Uses the given Function to extract a value from the object under test and creates a new assertion object using the given assert factory.

protected AssertionError

Returns:

The generated assertion error.
failure
(String
the error message to format
errorMessage
,
Object...
the arguments referenced by the format specifiers in the errorMessage string.
arguments
)

Generate a custom assertion error using the information in this assertion.

protected AssertionError

Returns:

The generated assertion error.
failureWithActualExpected
(Object
the actual object that was found during the test
actual
,
Object
the object that was expected
expected
,
String
the error message to format
errorMessageFormat
,
Object...
the arguments referenced by the format specifiers in the errorMessage string.
arguments
)

Generate a custom assertion error using the information in this assertion, using the given actual and expected values.

protected void
failWithActualExpectedAndMessage(Object
the actual object that was found during the test
actual
,
Object
the object that was expected
expected
,
String
the error message to format
errorMessageFormat
,
Object...
the arguments referenced by the format specifiers in the errorMessage string.
arguments
)

Throw an assertion error based on information in this assertion.

protected void
failWithMessage(String
the error message to format
errorMessage
,
Object...
the arguments referenced by the format specifiers in the errorMessage string.
arguments
)

Throw an assertion error based on information in this assertion.

public WritableAssertionInfo

Returns:

the WritableAssertionInfo used in the current assertion
getWritableAssertionInfo
()

Exposes the WritableAssertionInfo used in the current assertion for better extensibility.

public SELF
has(Condition<? super ACTUAL>
the given condition.
condition
)

Implements org.assertj.core.api.ExtensionPoints.has.

Verifies that the actual value satisfies the given condition.
public int

Returns:

1.
hashCode
()

Overrides java.lang.Object.hashCode.

Always returns 1.
public SELF
hasSameClassAs(Object
the object to check type against.
other
)

Implements org.assertj.core.api.Assert.hasSameClassAs.

Verifies that the actual value has the same class as the given object.
public SELF
hasSameHashCodeAs(Object
the object to check hashCode against.
other
)

Implements org.assertj.core.api.Assert.hasSameHashCodeAs.

Verifies that the actual object has the same hashCode as the given object.
public SELF
hasToString(String
the expected String description of actual.
expectedToString
)

Implements org.assertj.core.api.Assert.hasToString.

Verifies that actual actual.toString() is equal to the given String.
public SELF
hasToString(String
the format string to use.
expectedStringTemplate
,
Object...
the arguments to interpolate into the format string.
args
)

Implements org.assertj.core.api.Assert.hasToString.

Verifies that actual actual.toString() is equal to the given String when formatted with the given arguments.
protected SELF

Returns:

this assertion object.
inBinary
()

Use binary object representation instead of standard representation in error messages.

protected SELF

Returns:

this assertion object.
inHexadecimal
()

Use hexadecimal object representation instead of standard representation in error messages.

public SELF
is(Condition<? super ACTUAL>
the given condition.
condition
)

Implements org.assertj.core.api.ExtensionPoints.is.

Verifies that the actual value satisfies the given condition.
private boolean
protected boolean
public SELF
isEqualTo(Object
the given value to compare the actual value to.
expected
)

Implements org.assertj.core.api.Assert.isEqualTo.

Verifies that the actual value is equal to the given one.
public SELF
isExactlyInstanceOf(Class<?>
the type to check the actual value against.
type
)

Implements org.assertj.core.api.Assert.isExactlyInstanceOf.

Verifies that the actual value is exactly an instance of the given type.
public SELF
isIn(Object...
the given array to search the actual value in.
values
)

Implements org.assertj.core.api.Assert.isIn.

Verifies that the actual value is present in the given array of values.
public SELF
isIn(Iterable<?>
the given iterable to search the actual value in.
values
)

Implements org.assertj.core.api.Assert.isIn.

Verifies that the actual value is present in the given iterable.
public SELF
isInstanceOf(Class<?>
the type to check the actual value against.
type
)

Implements org.assertj.core.api.Assert.isInstanceOf.

Verifies that the actual value is an instance of the given type.
public SELF
isInstanceOfAny(Class<?>...
the types to check the actual value against.
types
)

Implements org.assertj.core.api.Assert.isInstanceOfAny.

Verifies that the actual value is an instance of any of the given types.
public <T> SELF
isInstanceOfSatisfying(Class<T>
the type to check the actual value against.
type
,
Consumer<T>
the requirements expressed as a Consumer.
requirements
)

Implements org.assertj.core.api.Assert.isInstanceOfSatisfying.

Verifies that the actual value is an instance of the given type satisfying the given requirements expressed as a Consumer.
public SELF
isNot(Condition<? super ACTUAL>
the given condition.
condition
)

Implements org.assertj.core.api.ExtensionPoints.isNot.

Verifies that the actual value does not satisfy the given condition.
public SELF
isNotEqualTo(Object
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.Assert.isNotEqualTo.

Verifies that the actual value is not equal to the given one.
public SELF
isNotExactlyInstanceOf(Class<?>
the type to check the actual value against.
type
)

Implements org.assertj.core.api.Assert.isNotExactlyInstanceOf.

Verifies that the actual value is not exactly an instance of given type.
public SELF
isNotIn(Object...
the given array to search the actual value in.
values
)

Implements org.assertj.core.api.Assert.isNotIn.

Verifies that the actual value is not present in the given array of values.
public SELF
isNotIn(Iterable<?>
the given iterable to search the actual value in.
values
)

Implements org.assertj.core.api.Assert.isNotIn.

Verifies that the actual value is not present in the given iterable.
public SELF
isNotInstanceOf(Class<?>
the type to check the actual value against.
type
)

Implements org.assertj.core.api.Assert.isNotInstanceOf.

Verifies that the actual value is not an instance of the given type.
public SELF
isNotInstanceOfAny(Class<?>...
the types to check the actual value against.
types
)

Implements org.assertj.core.api.Assert.isNotInstanceOfAny.

Verifies that the actual value is not an instance of any of the given types.
public SELF
isNotNull()

Implements org.assertj.core.api.Assert.isNotNull.

Verifies that the actual value is not null.
public SELF
isNotOfAnyClassIn(Class<?>...
the types to check the actual value against.
types
)

Implements org.assertj.core.api.Assert.isNotOfAnyClassIn.

Verifies that the actual value type is not in given types.
public SELF
isNotSameAs(Object
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.Assert.isNotSameAs.

Verifies that the actual value is not the same as the given one, i.e., using == comparison.
public void
isNull()

Implements org.assertj.core.api.Assert.isNull.

Verifies that the actual value is null.
public SELF
isOfAnyClassIn(Class<?>...
the types to check the actual value against.
types
)

Implements org.assertj.core.api.Assert.isOfAnyClassIn.

Verifies that the actual value type is in given types.
public SELF
isSameAs(Object
the given value to compare the actual value to.
expected
)

Implements org.assertj.core.api.Assert.isSameAs.

Verifies that the actual value is the same as the given one, i.e., using == comparison.
public SELF

Returns:

this assertion object.
matches
(Predicate<? super ACTUAL>
the Predicate to match
predicate
)

Verifies that the actual object matches the given predicate.

public SELF

Returns:

this assertion object.
matches
(Predicate<? super ACTUAL>
the Predicate to match
predicate
,
String
a description of the Predicate used in the error message
predicateDescription
)

Verifies that the actual object matches the given predicate, the predicate description is used to get an informative error message.

private SELF
matches(Predicate<? super ACTUAL> predicate, PredicateDescription predicateDescription)

private AssertionError
protected <
the type of elements.
E
>
AbstractListAssert<?, List<? extends E>, E, ObjectAssert<E>>

Returns:

a new AbstractListAssert.
newListAssertInstance
(List<? extends E>
new list under test
newActual
)

Create a AbstractListAssert from the given list.

public SELF

Returns:

this assertion object.
overridingErrorMessage
(String
the error message that will replace the default one provided by Assertj.
newErrorMessage
,
Object...
the args used to fill error message as in String#format(String, Object...).
args
)

Overrides AssertJ default error message by the given one.

public SELF

Returns:

this assertion object.
overridingErrorMessage
(Supplier<String>
the supplier supplies error message that will replace the default one provided by Assertj.
supplier
)

Overrides AssertJ default error message by the given one.

private void
private void
private void
public SELF
satisfies(Condition<? super ACTUAL>
the given condition.
condition
)

Implements org.assertj.core.api.ExtensionPoints.satisfies.

Verifies that the actual value satisfies the given condition.
public final SELF

Returns:

this assertion object.
satisfies
(Consumer<? super ACTUAL>...
to assert on the actual object - must not be null.
requirements
)

Verifies that the actual object satisfied the given requirements expressed as Consumers.

public final SELF

Returns:

this assertion object.
satisfies
(ThrowingConsumer<? super ACTUAL>...
the group of assertions to run against the object under test - must not be null.
assertions
)

Verifies that the actual object satisfied the given requirements expressed as ThrowingConsumers.

public final SELF

Returns:

this assertion object.
satisfiesAnyOf
(Consumer<? super ACTUAL>...
the group of assertions to run against the object under test - must not be null.
assertions
)

Verifies that the actual object under test satisfies at least one of the given assertions group expressed as Consumers.

public final SELF

Returns:

this assertion object.
satisfiesAnyOf
(ThrowingConsumer<? super ACTUAL>...
the group of assertions to run against the object under test - must not be null.
assertions
)

Verifies that the actual object under test satisfies at least one of the given assertions group expressed as ThrowingConsumers.

protected SELF
satisfiesAnyOfForProxy(Consumer<? super ACTUAL>[] assertionsGroups)

private boolean
satisfiesAssertions(Consumer<? super ACTUAL> assertions)

protected SELF
satisfiesForProxy(Consumer<? super ACTUAL>[] assertionsGroups)

public static void
public static void
public static void
setPrintAssertionsDescription(boolean printAssertionsDescription)

protected void
throwAssertionError(ErrorMessageFactory
used to define the error message.
errorMessageFactory
)

Utility method to throw an AssertionError given a BasicErrorMessageFactory.

public SELF
usingComparator(Comparator<? super ACTUAL>
the comparator to use for the incoming assertion checks.
customComparator
)

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingComparator(Comparator<? super ACTUAL>
the comparator to use for the incoming assertion checks.
customComparator
,
String
comparator description to be used in assertion error messages
customComparatorDescription
)

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingDefaultComparator()

Implements org.assertj.core.api.Assert.usingDefaultComparator.

Revert to standard comparison for the incoming assertion checks.
protected RecursiveAssertionAssert
protected RecursiveAssertionAssert
protected RecursiveComparisonAssert<?>
protected RecursiveComparisonAssert<?>
pack-priv SELF
withAssertionState(AbstractAssert<SELF extends AbstractAssert<SELF, ACTUAL>, ACTUAL> assertInstance)

public SELF

Returns:

this assertion object.
withFailMessage
(String
the error message that will replace the default one provided by Assertj.
newErrorMessage
,
Object...
the args used to fill error message as in String#format(String, Object...).
args
)

Alternative method for AbstractAssert#overridingErrorMessage

You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.

public SELF

Returns:

this assertion object.
withFailMessage
(Supplier<String>
the supplier supplies error message that will replace the default one provided by Assertj.
supplier
)

Alternative method for AbstractAssert#overridingErrorMessage

The new error message is only built if the assertion fails (by consuming the given supplier), this is useful if building messages is expensive.

public SELF
withRepresentation(Representation
Describe/represent values in AssertJ error messages.
representation
)

Implements org.assertj.core.api.Assert.withRepresentation.

Use the given Representation to describe/represent values in AssertJ error messages.
public SELF
withThreadDumpOnError()

Implements org.assertj.core.api.Assert.withThreadDumpOnError.

In case of an assertion error, a thread dump will be printed to System#err.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait