Package org.fest.assertions.internal
Class Failures
- java.lang.Object
-
- org.fest.assertions.internal.Failures
-
public class Failures extends java.lang.ObjectFailure actions.- Author:
- Yvonne Wang, Alex Ruiz
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.AssertionErrorfailure(java.lang.String message)Creates ausing the givenAssertionErrorStringas message.java.lang.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()java.lang.AssertionErrorfailure(AssertionInfo info, ErrorMessageFactory message)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()static Failuresinstance()Returns the singleton instance of this class.voidremoveFestRelatedElementsFromStackTraceIfNeeded(java.lang.AssertionError assertionError)If isremoveFestRelatedElementsFromStackTraceis true, it filters the stack trace of the givenAssertionErrorby removing stack trace elements related to Fest in order to get a more readable stack trace.voidsetRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace)Sets wether we remove elements related to Fest 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.
-
setRemoveFestRelatedElementsFromStackTrace
public void setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace)
Sets wether we remove elements related to Fest from assertion error stack trace.- Parameters:
removeFestRelatedElementsFromStackTrace- flag
-
failure
public java.lang.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 java.lang.AssertionError failure(AssertionInfo info, ErrorMessageFactory message)
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.message- knows how to create detail messages forAssertionErrors.- Returns:
- the created
.AssertionError
- creates a
-
failure
public java.lang.AssertionError failure(java.lang.String message)
Creates ausing the givenAssertionErrorStringas message.It filters the AssertionError stack trace be default, to have full stack trace use
setRemoveFestRelatedElementsFromStackTrace(boolean).- Parameters:
message- the message of theAssertionErrorto create.- Returns:
- the created
.AssertionError
-
removeFestRelatedElementsFromStackTraceIfNeeded
public void removeFestRelatedElementsFromStackTraceIfNeeded(java.lang.AssertionError assertionError)
If isremoveFestRelatedElementsFromStackTraceis true, it filters the stack trace of the givenAssertionErrorby removing stack trace elements related to Fest 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.fest.assertions.error.ConstructorInvoker.newInstance(ConstructorInvoker.java:34) at org.fest.assertions.error.ShouldBeEqual.newComparisonFailure(ShouldBeEqual.java:111) at org.fest.assertions.error.ShouldBeEqual.comparisonFailure(ShouldBeEqual.java:103) at org.fest.assertions.error.ShouldBeEqual.newAssertionError(ShouldBeEqual.java:81) at org.fest.assertions.internal.Failures.failure(Failures.java:76) at org.fest.assertions.internal.Objects.assertEqual(Objects.java:116) at org.fest.assertions.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 fromShouldBeEqual.newAssertionError(org.fest.assertions.description.Description)that is building a junit ComparisonFailure by reflection.- Parameters:
assertionError- theAssertionErrorto filter stack trace if option is set.
-
-