Class JPostmanStackTraceCleaner


  • public final class JPostmanStackTraceCleaner
    extends Object
    Builds short, clickable stack traces for annotation-driven failures.
    • 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 class
        testMethod - test method
        error - 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 class
        testMethod - test method
        error - original failure
        minimumStackTrace - true to keep only the first useful user-code frame
        includeSuppressed - 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.Call test body. The first stack frame should point to the actual assertion line, not the annotation line or JPostman proxy internals.
        Parameters:
        testClass - test class
        testMethod - test method
        error - original failure
        minimumStackTrace - true to keep only the first useful user-code frame
        includeSuppressed - 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 class
        testMethod - test or configuration method
        error - 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 class
        testMethod - test or configuration method
        error - original failure
        minimumStackTrace - 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:
        true for 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 class
        testMethod - test or configuration method
        root - 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 method
        methodName - Java method name to locate
        Returns:
        one-based source line number, or -1 when the source line cannot be found