Package org.assertj.core.api
Class AbstractSoftAssertions
- java.lang.Object
-
- org.assertj.core.api.AbstractSoftAssertions
-
- Direct Known Subclasses:
Java6AbstractBDDSoftAssertions,Java6AbstractStandardSoftAssertions
public class AbstractSoftAssertions extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected SoftProxiesproxies
-
Constructor Summary
Constructors Constructor Description AbstractSoftAssertions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddLineNumberToErrorMessage(java.lang.Throwable error)private java.util.List<java.lang.Throwable>addLineNumberToErrorMessages(java.util.List<java.lang.Throwable> errors)private java.lang.StringbuildErrorMessageWithLineNumber(java.lang.String originalErrorMessage, java.lang.StackTraceElement testStackTraceElement)private voidchangeErrorMessage(java.lang.Throwable error, java.lang.String errorMessageWithLineNumber)java.util.List<java.lang.Throwable>errorsCollected()Returns a copy of list of soft assertions collected errors.voidfail(java.lang.String failureMessage)Fails with the given message.voidfail(java.lang.String failureMessage, java.lang.Object... args)Fails with the given message built likeString.format(String, Object...).voidfail(java.lang.String failureMessage, java.lang.Throwable realCause)Fails with the given message and with theThrowablethat caused the failure.voidfailBecauseExceptionWasNotThrown(java.lang.Class<? extends java.lang.Throwable> throwableClass)Fails with a message explaining that aThrowableof given class was expected to be thrown but had not been.private java.lang.StackTraceElementgetFirstStackTraceElementFromTest(java.lang.StackTraceElement[] stacktrace)<T,V>
Vproxy(java.lang.Class<V> assertClass, java.lang.Class<T> actualClass, T actual)voidshouldHaveThrown(java.lang.Class<? extends java.lang.Throwable> throwableClass)Fails with a message explaining that aThrowableof given class was expected to be thrown but had not been.private java.lang.StringsimpleClassNameOf(java.lang.StackTraceElement testStackTraceElement)booleanwasSuccess()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
-
proxy
public <T,V> V proxy(java.lang.Class<V> assertClass, java.lang.Class<T> actualClass, T actual)
-
fail
public void fail(java.lang.String failureMessage)
Fails with the given message.- Parameters:
failureMessage- error message.- Since:
- 2.6.0 / 3.6.0
-
fail
public void fail(java.lang.String failureMessage, java.lang.Object... args)Fails with the given message built likeString.format(String, Object...).- Parameters:
failureMessage- error message.- Since:
- 2.6.0 / 3.6.0
-
fail
public void fail(java.lang.String failureMessage, java.lang.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(java.lang.Class<? extends java.lang.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:
java.lang.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(java.lang.Class<? extends java.lang.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:
java.lang.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
-
errorsCollected
public java.util.List<java.lang.Throwable> errorsCollected()
Returns a copy of list of soft assertions collected errors.- Returns:
- a copy of list of soft assertions collected errors.
-
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 java.util.List<java.lang.Throwable> addLineNumberToErrorMessages(java.util.List<java.lang.Throwable> errors)
-
addLineNumberToErrorMessage
private void addLineNumberToErrorMessage(java.lang.Throwable error)
-
buildErrorMessageWithLineNumber
private java.lang.String buildErrorMessageWithLineNumber(java.lang.String originalErrorMessage, java.lang.StackTraceElement testStackTraceElement)
-
changeErrorMessage
private void changeErrorMessage(java.lang.Throwable error, java.lang.String errorMessageWithLineNumber)
-
simpleClassNameOf
private java.lang.String simpleClassNameOf(java.lang.StackTraceElement testStackTraceElement)
-
getFirstStackTraceElementFromTest
private java.lang.StackTraceElement getFirstStackTraceElementFromTest(java.lang.StackTraceElement[] stacktrace)
-
-