public class Failures
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static Failures |
INSTANCE |
private static java.lang.String |
LINE_SEPARATOR |
private boolean |
printThreadDump
flag indicating that in case of a failure a threaddump is printed out.
|
private boolean |
removeAssertJRelatedElementsFromStackTrace
flag indicating whether or not we remove elements related to AssertJ from assertion error stack trace.
|
Constructor and Description |
---|
Failures() |
Modifier and Type | Method and Description |
---|---|
void |
enablePrintThreadDump()
Set the flag indicating that in case of a failure a threaddump is printed out.
|
java.lang.AssertionError |
failure(AssertionInfo info,
AssertionErrorFactory factory)
Creates a
following this pattern:
creates a using
as the error message if such value is not null , or
uses the given to create an ,
prepending the value of to the error message
|
java.lang.AssertionError |
failure(AssertionInfo info,
ErrorMessageFactory message)
Creates a
following this pattern:
creates a using
as the error message if such value is not null , or
uses the given to create the detail message of the
, prepending the value of to
the error message
|
java.lang.AssertionError |
failure(java.lang.String message)
Creates a
using the given String as message. |
java.lang.AssertionError |
failureIfErrorMessageIsOverridden(AssertionInfo info) |
static Failures |
instance()
Returns the singleton instance of this class.
|
private void |
printThreadDumpIfNeeded() |
void |
removeAssertJRelatedElementsFromStackTraceIfNeeded(java.lang.AssertionError assertionError)
If is
removeAssertJRelatedElementsFromStackTrace is true, it filters the stack trace of the given AssertionError
by removing stack trace elements related to AssertJ in order to get a more readable stack trace. |
void |
setRemoveAssertJRelatedElementsFromStackTrace(boolean removeAssertJRelatedElementsFromStackTrace)
Sets whether we remove elements related to AssertJ from assertion error stack trace.
|
private java.lang.String |
threadDumpDescription() |
private static final java.lang.String LINE_SEPARATOR
private static final Failures INSTANCE
private boolean printThreadDump
private boolean removeAssertJRelatedElementsFromStackTrace
public static Failures instance()
public void setRemoveAssertJRelatedElementsFromStackTrace(boolean removeAssertJRelatedElementsFromStackTrace)
removeAssertJRelatedElementsFromStackTrace
- flagpublic java.lang.AssertionError failure(AssertionInfo info, AssertionErrorFactory factory)
AssertionError
following this pattern:
AssertionError
using AssertionInfo.overridingErrorMessage()
as the error message if such value is not null
, orAssertionErrorFactory
to create an AssertionError
,
prepending the value of AssertionInfo.description()
to the error messageinfo
- contains information about the failed assertion.factory
- knows how to create AssertionError
s.AssertionError
.public java.lang.AssertionError failure(AssertionInfo info, ErrorMessageFactory message)
AssertionError
following this pattern:
AssertionError
using AssertionInfo.overridingErrorMessage()
as the error message if such value is not null
, orErrorMessageFactory
to create the detail message of the
AssertionError
, prepending the value of AssertionInfo.description()
to
the error messageinfo
- contains information about the failed assertion.message
- knows how to create detail messages for AssertionError
s.AssertionError
.public java.lang.AssertionError failureIfErrorMessageIsOverridden(AssertionInfo info)
public java.lang.AssertionError failure(java.lang.String message)
AssertionError
using the given String
as message.
It filters the AssertionError stack trace be default, to have full stack trace use
setRemoveAssertJRelatedElementsFromStackTrace(boolean)
.
message
- the message of the AssertionError
to create.AssertionError
.private void printThreadDumpIfNeeded()
public void removeAssertJRelatedElementsFromStackTraceIfNeeded(java.lang.AssertionError assertionError)
removeAssertJRelatedElementsFromStackTrace
is true, it filters the stack trace of the given AssertionError
by removing stack trace elements related to AssertJ in order to get a more readable stack trace.
See example below :
--------------- 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)
Method is public because we need to call it from ShouldBeEqual.newAssertionError(Description, org.assertj.core.presentation.Representation)
that is building a junit ComparisonFailure by reflection.assertionError
- the AssertionError
to filter stack trace if option is set.public void enablePrintThreadDump()
private java.lang.String threadDumpDescription()