Package org.assertj.core.internal
Class Failures
- java.lang.Object
-
- org.assertj.core.internal.Failures
-
public class Failures extends Object
Failure actions.- Author:
- Yvonne Wang, Alex Ruiz
-
-
Field Summary
Fields Modifier and Type Field Description private AssertionErrorCreatorassertionErrorCreatorprivate static FailuresINSTANCEprivate static StringLINE_SEPARATORprivate booleanprintThreadDumpflag indicating that in case of a failure a threaddump is printed out.private booleanremoveAssertJRelatedElementsFromStackTraceflag indicating whether or not we remove elements related to AssertJ from assertion error stack trace.
-
Constructor Summary
Constructors Constructor Description Failures()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringassertionErrorMessage(AssertionInfo info, ErrorMessageFactory messageFactory)voidenablePrintThreadDump()Set the flag indicating that in case of a failure a threaddump is printed out.AssertionErrorexpectedThrowableNotThrown(Class<? extends Throwable> throwableClass)Creates afor aAssertionErrorThrowableclass that was expected to be thrown.AssertionErrorfailure(String message)Creates ausing the givenAssertionErrorStringas message.AssertionErrorfailure(AssertionInfo info, AssertionErrorFactory factory)Creates afollowing this pattern: creates aAssertionErrorusingAssertionErroras the error message if such value is notAssertionInfo.overridingErrorMessage()null, or uses the givento create anAssertionErrorFactory, prepending the value ofAssertionErrorto the error messageAssertionInfo.description()AssertionErrorfailure(AssertionInfo info, ErrorMessageFactory messageFactory)Creates afollowing this pattern: creates aAssertionErrorusingAssertionErroras the error message if such value is notAssertionInfo.overridingErrorMessage()null, or uses the givento create the detail message of theErrorMessageFactory, prepending the value ofAssertionErrorto the error messageAssertionInfo.description()AssertionErrorfailure(AssertionInfo info, ErrorMessageFactory messageFactory, Object actual, Object expected)AssertionErrorfailureIfErrorMessageIsOverridden(AssertionInfo info)static Failuresinstance()Returns the singleton instance of this class.booleanisRemoveAssertJRelatedElementsFromStackTrace()Returns whether or not we remove elements related to AssertJ from assertion error stack trace.voidprintThreadDumpIfNeeded()voidremoveAssertJRelatedElementsFromStackTraceIfNeeded(AssertionError assertionError)If isremoveAssertJRelatedElementsFromStackTraceis true, it filters the stack trace of the givenAssertionErrorby removing stack trace elements related to AssertJ in order to get a more readable stack trace.voidsetRemoveAssertJRelatedElementsFromStackTrace(boolean removeAssertJRelatedElementsFromStackTrace)Sets whether we remove elements related to AssertJ from assertion error stack trace.static StringthreadDumpDescription()
-
-
-
Field Detail
-
LINE_SEPARATOR
private static final String LINE_SEPARATOR
-
INSTANCE
private static final Failures INSTANCE
-
assertionErrorCreator
private AssertionErrorCreator assertionErrorCreator
-
printThreadDump
private boolean printThreadDump
flag indicating that in case of a failure a threaddump is printed out.
-
removeAssertJRelatedElementsFromStackTrace
private boolean removeAssertJRelatedElementsFromStackTrace
flag indicating whether or not we remove elements related to AssertJ from assertion error stack trace.
-
-
Method Detail
-
instance
public static Failures instance()
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
setRemoveAssertJRelatedElementsFromStackTrace
public void setRemoveAssertJRelatedElementsFromStackTrace(boolean removeAssertJRelatedElementsFromStackTrace)
Sets whether we remove elements related to AssertJ from assertion error stack trace.- Parameters:
removeAssertJRelatedElementsFromStackTrace- flag
-
isRemoveAssertJRelatedElementsFromStackTrace
public boolean isRemoveAssertJRelatedElementsFromStackTrace()
Returns whether or not we remove elements related to AssertJ from assertion error stack trace.- Returns:
- whether or not we remove elements related to AssertJ from assertion error stack trace.
-
failure
public AssertionError failure(AssertionInfo info, AssertionErrorFactory factory)
Creates afollowing this pattern:AssertionError- creates a
usingAssertionErroras the error message if such value is notAssertionInfo.overridingErrorMessage()null, or - uses the given
to create anAssertionErrorFactory, prepending the value ofAssertionErrorto the error messageAssertionInfo.description()
- Parameters:
info- contains information about the failed assertion.factory- knows how to createAssertionErrors.- Returns:
- the created
.AssertionError
- creates a
-
failure
public AssertionError failure(AssertionInfo info, ErrorMessageFactory messageFactory)
Creates afollowing this pattern:AssertionError- creates a
usingAssertionErroras the error message if such value is notAssertionInfo.overridingErrorMessage()null, or - uses the given
to create the detail message of theErrorMessageFactory, prepending the value ofAssertionErrorto the error messageAssertionInfo.description()
- Parameters:
info- contains information about the failed assertion.messageFactory- knows how to create detail messages forAssertionErrors.- Returns:
- the created
.AssertionError
- creates a
-
failure
public AssertionError failure(AssertionInfo info, ErrorMessageFactory messageFactory, Object actual, Object expected)
-
assertionErrorMessage
protected String assertionErrorMessage(AssertionInfo info, ErrorMessageFactory messageFactory)
-
failureIfErrorMessageIsOverridden
public AssertionError failureIfErrorMessageIsOverridden(AssertionInfo info)
-
failure
public AssertionError failure(String message)
Creates ausing the givenAssertionErrorStringas message.It filters the AssertionError stack trace be default, to have full stack trace use
setRemoveAssertJRelatedElementsFromStackTrace(boolean).- Parameters:
message- the message of theAssertionErrorto create.- Returns:
- the created
.AssertionError
-
expectedThrowableNotThrown
public AssertionError expectedThrowableNotThrown(Class<? extends Throwable> throwableClass)
Creates afor aAssertionErrorThrowableclass that was expected to be thrown.- Parameters:
throwableClass- the Throwable class that was expected to be thrown.- Returns:
- the created
.AssertionError - Since:
- 2.6.0 / 3.6.0
-
printThreadDumpIfNeeded
public void printThreadDumpIfNeeded()
-
removeAssertJRelatedElementsFromStackTraceIfNeeded
public void removeAssertJRelatedElementsFromStackTraceIfNeeded(AssertionError assertionError)
If isremoveAssertJRelatedElementsFromStackTraceis true, it filters the stack trace of the givenAssertionErrorby removing stack trace elements related to AssertJ in order to get a more readable stack trace.See example below :
Method is public because we need to call it from--------------- stack trace not filtered ----------------- org.junit.ComparisonFailure: expected:<'[Ronaldo]'> but was:<'[Messi]'> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:501) at org.assertj.core.error.ConstructorInvoker.newInstance(ConstructorInvoker.java:34) at org.assertj.core.error.ShouldBeEqual.newComparisonFailure(ShouldBeEqual.java:111) at org.assertj.core.error.ShouldBeEqual.comparisonFailure(ShouldBeEqual.java:103) at org.assertj.core.error.ShouldBeEqual.newAssertionError(ShouldBeEqual.java:81) at org.assertj.core.internal.Failures.failure(Failures.java:76) at org.assertj.core.internal.Objects.assertEqual(Objects.java:116) at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:74) at examples.StackTraceFilterExample.main(StackTraceFilterExample.java:13) --------------- stack trace filtered ----------------- org.junit.ComparisonFailure: expected:<'[Ronaldo]'> but was:<'[Messi]'> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at examples.StackTraceFilterExample.main(StackTraceFilterExample.java:20)ShouldBeEqual.newAssertionError(Description, org.assertj.core.presentation.Representation)that is building a junit ComparisonFailure by reflection.- Parameters:
assertionError- theAssertionErrorto filter stack trace if option is set.
-
enablePrintThreadDump
public void enablePrintThreadDump()
Set the flag indicating that in case of a failure a threaddump is printed out.
-
threadDumpDescription
public static String threadDumpDescription()
-
-