Package org.assertj.core.api
Class AbstractSoftAssertions
- java.lang.Object
-
- org.assertj.core.api.AbstractSoftAssertions
-
- All Implemented Interfaces:
InstanceOfAssertFactories
- Direct Known Subclasses:
Java6AbstractBDDSoftAssertions
,Java6AbstractStandardSoftAssertions
public class AbstractSoftAssertions extends Object implements InstanceOfAssertFactories
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AbstractSoftAssertions.ThrowingRunnable
-
Field Summary
Fields Modifier and Type Field Description protected SoftProxies
proxies
-
Fields inherited from interface org.assertj.core.api.InstanceOfAssertFactories
ARRAY, ATOMIC_BOOLEAN, ATOMIC_INTEGER, ATOMIC_INTEGER_ARRAY, ATOMIC_INTEGER_FIELD_UPDATER, ATOMIC_LONG, ATOMIC_LONG_ARRAY, ATOMIC_LONG_FIELD_UPDATER, ATOMIC_MARKABLE_REFERENCE, ATOMIC_REFERENCE, ATOMIC_REFERENCE_ARRAY, ATOMIC_REFERENCE_FIELD_UPDATER, ATOMIC_STAMPED_REFERENCE, BIG_DECIMAL, BIG_INTEGER, BOOLEAN, BOOLEAN_ARRAY, BYTE, BYTE_ARRAY, CHAR_ARRAY, CHAR_SEQUENCE, CHARACTER, CLASS, COMPLETABLE_FUTURE, COMPLETION_STAGE, DATE, DOUBLE, DOUBLE_ARRAY, DOUBLE_PREDICATE, DOUBLE_STREAM, FILE, FLOAT, FLOAT_ARRAY, FUTURE, INPUT_STREAM, INSTANT, INT_ARRAY, INT_PREDICATE, INT_STREAM, INTEGER, ITERABLE, ITERATOR, LIST, LOCAL_DATE, LOCAL_DATE_TIME, LOCAL_TIME, LONG, LONG_ARRAY, LONG_PREDICATE, LONG_STREAM, MAP, OFFSET_DATE_TIME, OFFSET_TIME, OPTIONAL, OPTIONAL_DOUBLE, OPTIONAL_INT, OPTIONAL_LONG, PATH, PREDICATE, SHORT, SHORT_ARRAY, SPLITERATOR, STREAM, STRING, STRING_BUFFER, STRING_BUILDER, THROWABLE, URI_TYPE, URL_TYPE, ZONED_DATE_TIME
-
-
Constructor Summary
Constructors Constructor Description AbstractSoftAssertions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Throwable
addLineNumberToErrorMessage(Throwable error)
private List<Throwable>
addLineNumberToErrorMessages(List<Throwable> errors)
private String
buildErrorMessageWithLineNumber(String originalErrorMessage, StackTraceElement testStackTraceElement)
void
check(AbstractSoftAssertions.ThrowingRunnable assertion)
Catch and collect assertion errors coming from standard and custom assertions.private Throwable
createNewInstanceWithLineNumberInErrorMessage(Throwable error, StackTraceElement testStackTraceElement)
protected List<Throwable>
decorateErrorsCollected(List<Throwable> errors)
Modifies collected errors.List<Throwable>
errorsCollected()
Returns a copy of list of soft assertions collected errors.void
fail(String failureMessage)
Fails with the given message.void
fail(String failureMessage, Object... args)
Fails with the given message built likeString.format(String, Object...)
.void
fail(String failureMessage, Throwable realCause)
Fails with the given message and with theThrowable
that caused the failure.void
failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass)
Fails with a message explaining that aThrowable
of given class was expected to be thrown but had not been.private StackTraceElement
getFirstStackTraceElementFromTest(StackTraceElement[] stacktrace)
private boolean
isProxiedAssertionClass(String className)
<T,V>
Vproxy(Class<V> assertClass, Class<T> actualClass, T actual)
void
shouldHaveThrown(Class<? extends Throwable> throwableClass)
Fails with a message explaining that aThrowable
of given class was expected to be thrown but had not been.private String
simpleClassNameOf(StackTraceElement testStackTraceElement)
boolean
wasSuccess()
Returns the result of last soft assertion which can be used to decide what the next one should be.
-
-
-
Field Detail
-
proxies
protected final SoftProxies proxies
-
-
Method Detail
-
check
public void check(AbstractSoftAssertions.ThrowingRunnable assertion)
Catch and collect assertion errors coming from standard and custom assertions.Example :
SoftAssertions softly = new SoftAssertions(); softly.check(() -> Assertions.assertThat(…).…); softly.check(() -> CustomAssertions.assertThat(…).…); softly.assertAll();
- Parameters:
assertion
- an assertion call.
-
fail
public void fail(String failureMessage)
Fails with the given message.- Parameters:
failureMessage
- error message.- Since:
- 2.6.0 / 3.6.0
-
fail
public void fail(String failureMessage, Object... args)
Fails with the given message built likeString.format(String, Object...)
.- Parameters:
failureMessage
- error message.args
- Arguments referenced by the format specifiers in the format string.- Since:
- 2.6.0 / 3.6.0
-
fail
public void fail(String failureMessage, Throwable realCause)
Fails with the given message and with theThrowable
that caused the failure.- Parameters:
failureMessage
- error message.realCause
- cause of the error.- Since:
- 2.6.0 / 3.6.0
-
failBecauseExceptionWasNotThrown
public void failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass)
Fails with a message explaining that aThrowable
of given class was expected to be thrown but had not been.- Parameters:
throwableClass
- the Throwable class that was expected to be thrown.- Throws:
AssertionError
- with a message explaining that aThrowable
of given class was expected to be thrown but had not been.- Since:
- 2.6.0 / 3.6.0
Fail.shouldHaveThrown(Class)
can be used as a replacement.
-
shouldHaveThrown
public void shouldHaveThrown(Class<? extends Throwable> throwableClass)
Fails with a message explaining that aThrowable
of given class was expected to be thrown but had not been.- Parameters:
throwableClass
- the Throwable class that was expected to be thrown.- Throws:
AssertionError
- with a message explaining that aThrowable
of given class was expected to be thrown but had not been.- Since:
- 2.6.0 / 3.6.0
-
errorsCollected
public List<Throwable> errorsCollected()
Returns a copy of list of soft assertions collected errors.- Returns:
- a copy of list of soft assertions collected errors.
-
decorateErrorsCollected
protected List<Throwable> decorateErrorsCollected(List<Throwable> errors)
Modifies collected errors. Override to customize modification.- Parameters:
errors
- list of errors to decorate- Returns:
- decorated list
-
wasSuccess
public boolean wasSuccess()
Returns the result of last soft assertion which can be used to decide what the next one should be.Example :
Person person = ... SoftAssertions soft = new SoftAssertions(); if (soft.assertThat(person.getAddress()).isNotNull().wasSuccess()) { soft.assertThat(person.getAddress().getStreet()).isNotNull(); }
- Returns:
- true if the last assertion was a success.
-
addLineNumberToErrorMessages
private List<Throwable> addLineNumberToErrorMessages(List<Throwable> errors)
-
createNewInstanceWithLineNumberInErrorMessage
private Throwable createNewInstanceWithLineNumberInErrorMessage(Throwable error, StackTraceElement testStackTraceElement) throws ReflectiveOperationException
- Throws:
ReflectiveOperationException
-
buildErrorMessageWithLineNumber
private String buildErrorMessageWithLineNumber(String originalErrorMessage, StackTraceElement testStackTraceElement)
-
simpleClassNameOf
private String simpleClassNameOf(StackTraceElement testStackTraceElement)
-
getFirstStackTraceElementFromTest
private StackTraceElement getFirstStackTraceElementFromTest(StackTraceElement[] stacktrace)
-
isProxiedAssertionClass
private boolean isProxiedAssertionClass(String className)
-
-