Package org.junit.internal
Class Throwables
- java.lang.Object
-
- org.junit.internal.Throwables
-
public final class Throwables extends java.lang.ObjectMiscellaneous functions dealing withThrowable.- Since:
- 4.12
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classThrowables.State
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.reflect.MethodgetSuppressedprivate static java.lang.String[]REFLECTION_METHOD_NAME_PREFIXESprivate static java.lang.String[]TEST_FRAMEWORK_METHOD_NAME_PREFIXESprivate static java.lang.String[]TEST_FRAMEWORK_TEST_METHOD_NAME_PREFIXES
-
Constructor Summary
Constructors Modifier Constructor Description privateThrowables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidappendStackTraceLines(java.util.List<java.lang.String> stackTraceLines, java.lang.StringBuilder destBuilder)private static <T> java.util.List<T>asReversedList(java.util.List<T> list)private static java.util.List<java.lang.String>getCauseStackTraceLines(java.lang.Throwable exception)private static java.lang.StringgetFullStackTrace(java.lang.Throwable exception)static java.lang.StringgetStacktrace(java.lang.Throwable exception)Returns the stacktrace of the given Throwable as a String.static java.lang.StringgetTrimmedStackTrace(java.lang.Throwable exception)Gets a trimmed version of the stack trace of the given exception.private static java.util.List<java.lang.String>getTrimmedStackTraceLines(java.lang.Throwable exception)private static booleanhasSuppressed(java.lang.Throwable exception)private static java.lang.reflect.MethodinitGetSuppressed()private static booleanisMatchingMethod(java.lang.String methodName, java.lang.String[] methodNamePrefixes)private static booleanisReflectionMethod(java.lang.String methodName)private static booleanisTestFrameworkMethod(java.lang.String methodName)private static <T extends java.lang.Throwable>
voidrethrow(java.lang.Throwable e)static java.lang.ExceptionrethrowAsException(java.lang.Throwable e)Rethrows the givenThrowable, allowing the caller to declare that it throwsException.
-
-
-
Field Detail
-
getSuppressed
private static final java.lang.reflect.Method getSuppressed
-
TEST_FRAMEWORK_METHOD_NAME_PREFIXES
private static final java.lang.String[] TEST_FRAMEWORK_METHOD_NAME_PREFIXES
-
TEST_FRAMEWORK_TEST_METHOD_NAME_PREFIXES
private static final java.lang.String[] TEST_FRAMEWORK_TEST_METHOD_NAME_PREFIXES
-
REFLECTION_METHOD_NAME_PREFIXES
private static final java.lang.String[] REFLECTION_METHOD_NAME_PREFIXES
-
-
Method Detail
-
rethrowAsException
public static java.lang.Exception rethrowAsException(java.lang.Throwable e) throws java.lang.ExceptionRethrows the givenThrowable, allowing the caller to declare that it throwsException. This is useful when your callers have nothing reasonable they can do when aThrowableis thrown. This is declared to returnExceptionso it can be used in athrowclause:try { doSomething(); } catch (Throwable e} { throw Throwables.rethrowAsException(e); } doSomethingLater();- Parameters:
e- exception to rethrow- Returns:
- does not return anything
- Throws:
java.lang.Exception- Since:
- 4.12
-
rethrow
private static <T extends java.lang.Throwable> void rethrow(java.lang.Throwable e) throws T extends java.lang.Throwable- Throws:
T extends java.lang.Throwable
-
getStacktrace
public static java.lang.String getStacktrace(java.lang.Throwable exception)
Returns the stacktrace of the given Throwable as a String.- Since:
- 4.13
-
getTrimmedStackTrace
public static java.lang.String getTrimmedStackTrace(java.lang.Throwable exception)
Gets a trimmed version of the stack trace of the given exception. Stack trace elements that are below the test method are filtered out.- Returns:
- a trimmed stack trace, or the original trace if trimming wasn't possible
-
getTrimmedStackTraceLines
private static java.util.List<java.lang.String> getTrimmedStackTraceLines(java.lang.Throwable exception)
-
initGetSuppressed
private static java.lang.reflect.Method initGetSuppressed()
-
hasSuppressed
private static boolean hasSuppressed(java.lang.Throwable exception)
-
getCauseStackTraceLines
private static java.util.List<java.lang.String> getCauseStackTraceLines(java.lang.Throwable exception)
-
getFullStackTrace
private static java.lang.String getFullStackTrace(java.lang.Throwable exception)
-
appendStackTraceLines
private static void appendStackTraceLines(java.util.List<java.lang.String> stackTraceLines, java.lang.StringBuilder destBuilder)
-
asReversedList
private static <T> java.util.List<T> asReversedList(java.util.List<T> list)
-
isTestFrameworkMethod
private static boolean isTestFrameworkMethod(java.lang.String methodName)
-
isReflectionMethod
private static boolean isReflectionMethod(java.lang.String methodName)
-
isMatchingMethod
private static boolean isMatchingMethod(java.lang.String methodName, java.lang.String[] methodNamePrefixes)
-
-