Package org.assertj.core.api
Class AbstractSoftAssertions
- java.lang.Object
-
- org.assertj.core.api.AbstractSoftAssertions
-
- All Implemented Interfaces:
AssertionErrorCollector,InstanceOfAssertFactories,SoftAssertionsProvider
- Direct Known Subclasses:
BDDSoftAssertions,Java6BDDSoftAssertions,Java6JUnitBDDSoftAssertions,Java6JUnitSoftAssertions,Java6SoftAssertions,JUnitBDDSoftAssertions,JUnitJupiterBDDSoftAssertions,JUnitJupiterSoftAssertions,JUnitSoftAssertions,SoftAssertions
public abstract class AbstractSoftAssertions extends Object implements SoftAssertionsProvider, InstanceOfAssertFactories
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.assertj.core.api.SoftAssertionsProvider
SoftAssertionsProvider.ThrowingRunnable
-
-
Field Summary
Fields Modifier and Type Field Description private AssertionErrorCreatorassertionErrorCreatorprotected SoftProxiesproxies-
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, DURATION, 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_ADDER, 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 <T extends Throwable>
TaddLineNumberToErrorMessage(T error)private <T extends Throwable>
List<T>addLineNumberToErrorMessages(List<? extends T> errors)voidassertAll()Verifies that no soft assertions have failed.List<AssertionError>assertionErrorsCollected()Returns a copy of list of soft assertions collected errors.private StringbuildErrorMessageWithLineNumber(String originalErrorMessage, StackTraceElement testStackTraceElement)voidcollectAssertionError(AssertionError error)private <T extends Throwable>
TcreateNewInstanceWithLineNumberInErrorMessage(T error, StackTraceElement testStackTraceElement)protected <T extends Throwable>
List<T>decorateErrorsCollected(List<? extends T> errors)Modifies collected errors.List<Throwable>errorsCollected()Returns a copy of list of soft assertions collected errors.voidfail(String failureMessage)Fails with the given message.voidfail(String failureMessage, Object... args)Fails with the given message built likeString.format(String, Object...).voidfail(String failureMessage, Throwable realCause)Fails with the given message and with theThrowablethat caused the failure.voidfailBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass)Fails with a message explaining that aThrowableof given class was expected to be thrown but had not been.private StackTraceElementgetFirstStackTraceElementFromTest(StackTraceElement[] stacktrace)private booleanisProxiedAssertionClass(String className)<SELF extends Assert<? extends SELF,? extends ACTUAL>,ACTUAL>
SELFproxy(Class<SELF> assertClass, Class<ACTUAL> actualClass, ACTUAL actual)Creates a proxied assertion class of the given type.voidshouldHaveThrown(Class<? extends Throwable> throwableClass)Fails with a message explaining that aThrowableof given class was expected to be thrown but had not been.private StringsimpleClassNameOf(StackTraceElement testStackTraceElement)booleanwasSuccess()Returns the result of last soft assertion which can be used to decide what the next one should be.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.assertj.core.api.SoftAssertionsProvider
assertAlso, check
-
-
-
-
Field Detail
-
proxies
protected final SoftProxies proxies
-
assertionErrorCreator
private final AssertionErrorCreator assertionErrorCreator
-
-
Method Detail
-
assertAll
public void assertAll()
Description copied from interface:SoftAssertionsProviderVerifies that no soft assertions have failed.- Specified by:
assertAllin interfaceSoftAssertionsProvider
-
proxy
public <SELF extends Assert<? extends SELF,? extends ACTUAL>,ACTUAL> SELF proxy(Class<SELF> assertClass, Class<ACTUAL> actualClass, ACTUAL actual)
Description copied from interface:SoftAssertionsProviderCreates a proxied assertion class of the given type. The returned value is an assertion object compatible with the supplied assertion class, but instead of throwing errors it will collect them and store them usingcollectAssertionError().- Specified by:
proxyin interfaceSoftAssertionsProvider- Type Parameters:
SELF- The type of the assertion classACTUAL- The type of the object-under-test- Parameters:
assertClass- Class instance for the assertion type.actualClass- Class instance for the type of the object-under-test.actual- The actual object-under-test.- Returns:
- A proxied assertion class for the given object-under-test.
-
collectAssertionError
public void collectAssertionError(AssertionError error)
- Specified by:
collectAssertionErrorin interfaceAssertionErrorCollector
-
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 theThrowablethat 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 aThrowableof 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 aThrowableof 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 aThrowableof 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 aThrowableof given class was expected to be thrown but had not been.- Since:
- 2.6.0 / 3.6.0
-
assertionErrorsCollected
public List<AssertionError> assertionErrorsCollected()
Returns a copy of list of soft assertions collected errors.- Specified by:
assertionErrorsCollectedin interfaceAssertionErrorCollector- Returns:
- a copy of list of soft assertions collected errors.
-
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 <T extends Throwable> List<T> decorateErrorsCollected(List<? extends T> errors)
Modifies collected errors. Override to customize modification.- Type Parameters:
T- the supertype to use in the list return value- 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(); }- Specified by:
wasSuccessin interfaceSoftAssertionsProvider- Returns:
- true if the last assertion was a success.
-
addLineNumberToErrorMessages
private <T extends Throwable> List<T> addLineNumberToErrorMessages(List<? extends T> errors)
-
addLineNumberToErrorMessage
private <T extends Throwable> T addLineNumberToErrorMessage(T error)
-
createNewInstanceWithLineNumberInErrorMessage
private <T extends Throwable> T createNewInstanceWithLineNumberInErrorMessage(T 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)
-
-