Package io.jpostman.annotations.runtime
Class JPostmanStackTraceCleaner
- java.lang.Object
-
- io.jpostman.annotations.runtime.JPostmanStackTraceCleaner
-
public final class JPostmanStackTraceCleaner extends Object
Builds short, clickable stack traces for annotation-driven failures.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AssertionErrorcleanFailure(Class<?> testClass, Method testMethod, Throwable error)Creates a clean assertion failure for a test method.static AssertionErrorcleanFailure(Class<?> testClass, Method testMethod, Throwable error, boolean minimumStackTrace, boolean includeSuppressed)Creates a clean assertion failure with selectable verbosity.static AssertionErrorcleanRuntimeFailure(Class<?> testClass, Method testMethod, Throwable error, boolean minimumStackTrace, boolean includeSuppressed)Creates a clean assertion failure for assertions executed from inside a runtime@JPostman.Calltest body.static StackTraceElement[]cleanStack(Class<?> testClass, Method testMethod, Throwable root)Builds a cleaned stack trace for a framework throwable.static ThrowablecleanThrowable(Class<?> testClass, Method testMethod, Throwable error)Cleans a normal test-method or configuration-method failure without mutating the original throwable.static ThrowablecleanThrowable(Class<?> testClass, Method testMethod, Throwable error, boolean minimumStackTrace)Cleans a normal throwable with selectable stack verbosity.static intfindSourceLine(Class<?> testClass, String methodName)Finds the source line number for a method in the local source tree.static booleanisJUnitSkip(Throwable throwable)Returns true when the throwable represents a JUnit skipped/aborted test.static ThrowablerootCause(Throwable throwable)Returns the root cause, unwrapping reflection wrappers.
-
-
-
Method Detail
-
cleanFailure
public static AssertionError cleanFailure(Class<?> testClass, Method testMethod, Throwable error)
Creates a clean assertion failure for a test method.- Parameters:
testClass- test classtestMethod- test methoderror- original failure- Returns:
- assertion error with a short stack trace
-
cleanFailure
public static AssertionError cleanFailure(Class<?> testClass, Method testMethod, Throwable error, boolean minimumStackTrace, boolean includeSuppressed)
Creates a clean assertion failure with selectable verbosity.- Parameters:
testClass- test classtestMethod- test methoderror- original failureminimumStackTrace- true to keep only the first useful user-code frameincludeSuppressed- true to append suppressed diagnostic messages- Returns:
- assertion error with cleaned output
-
cleanRuntimeFailure
public static AssertionError cleanRuntimeFailure(Class<?> testClass, Method testMethod, Throwable error, boolean minimumStackTrace, boolean includeSuppressed)
Creates a clean assertion failure for assertions executed from inside a runtime@JPostman.Calltest body. The first stack frame should point to the actual assertion line, not the annotation line or JPostman proxy internals.- Parameters:
testClass- test classtestMethod- test methoderror- original failureminimumStackTrace- true to keep only the first useful user-code frameincludeSuppressed- true to append suppressed diagnostic messages- Returns:
- assertion error with cleaned output
-
cleanThrowable
public static Throwable cleanThrowable(Class<?> testClass, Method testMethod, Throwable error)
Cleans a normal test-method or configuration-method failure without mutating the original throwable.TestNG can reuse the same configuration failure for skipped test results. If we mutate the original throwable stack trace, the original configuration failure can later point to the wrong test method. This method creates a display copy instead.
- Parameters:
testClass- test classtestMethod- test or configuration methoderror- original failure- Returns:
- copied throwable with a short stack trace
-
cleanThrowable
public static Throwable cleanThrowable(Class<?> testClass, Method testMethod, Throwable error, boolean minimumStackTrace)
Cleans a normal throwable with selectable stack verbosity.- Parameters:
testClass- test classtestMethod- test or configuration methoderror- original failureminimumStackTrace- true to keep only the first useful user-code frame- Returns:
- copied throwable with cleaned output
-
isJUnitSkip
public static boolean isJUnitSkip(Throwable throwable)
Returns true when the throwable represents a JUnit skipped/aborted test.- Parameters:
throwable- throwable to inspect- Returns:
truefor JUnit abort/skip exceptions
-
rootCause
public static Throwable rootCause(Throwable throwable)
Returns the root cause, unwrapping reflection wrappers.- Parameters:
throwable- original throwable- Returns:
- root throwable
-
cleanStack
public static StackTraceElement[] cleanStack(Class<?> testClass, Method testMethod, Throwable root)
Builds a cleaned stack trace for a framework throwable.- Parameters:
testClass- test classtestMethod- test or configuration methodroot- throwable to clean- Returns:
- cleaned stack trace
-
findSourceLine
public static int findSourceLine(Class<?> testClass, String methodName)
Finds the source line number for a method in the local source tree.This is a best-effort helper used to make cleaned assertion failures point at the user's test method. It searches common Maven source roots from the current working directory upward.
- Parameters:
testClass- test class that owns the methodmethodName- Java method name to locate- Returns:
- one-based source line number, or
-1when the source line cannot be found
-
-