public final class Throwables
extends java.lang.Object
Throwable
s.Modifier | Constructor and Description |
---|---|
private |
Throwables() |
Modifier and Type | Method and Description |
---|---|
static void |
appendStackTraceInCurentThreadToThrowable(java.lang.Throwable t,
java.lang.String methodToStartFrom)
Appends the stack trace of the current thread to the one in the given
. |
static java.lang.Throwable |
getRootCause(java.lang.Throwable throwable)
Get the root cause (ie the last non null cause) from a
Throwable . |
static void |
removeAssertJRelatedElementsFromStackTrace(java.lang.Throwable throwable)
Removes the AssertJ-related elements from the
stack trace that have little value for
end user. |
private static java.util.List<java.lang.StackTraceElement> |
stackTraceInCurrentThread() |
private static java.util.List<java.lang.StackTraceElement> |
stackTraceInCurrentThread(java.lang.String methodToStartFrom) |
public static void appendStackTraceInCurentThreadToThrowable(java.lang.Throwable t, java.lang.String methodToStartFrom)
Throwable
.t
- the given Throwable
.methodToStartFrom
- the name of the method used as the starting point of the current thread's stack trace.private static java.util.List<java.lang.StackTraceElement> stackTraceInCurrentThread(java.lang.String methodToStartFrom)
private static java.util.List<java.lang.StackTraceElement> stackTraceInCurrentThread()
public static void removeAssertJRelatedElementsFromStackTrace(java.lang.Throwable throwable)
Throwable
stack trace that have little value for
end user. Therefore, instead of seeing this:
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)
We get this:
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)
throwable
- the Throwable
to filter stack trace.public static java.lang.Throwable getRootCause(java.lang.Throwable throwable)
Throwable
.throwable
- the Throwable
to get root cause from.null
.