Class ReportPrinter

java.lang.Object
rife.bld.extension.junitreporter.ReportPrinter

@NullMarked public final class ReportPrinter extends Object
Utility class for printing detailed and structured reports of test failures.

All index parameters are 0-based internally. Public methods printDetails(java.lang.String, java.util.Map<java.lang.String, rife.bld.extension.junitreporter.TestClassFailures>) and hasIndex(java.lang.String, java.util.Map<java.lang.String, rife.bld.extension.junitreporter.TestClassFailures>) accept 1-based indices from CLI input.

Index format: N for group N, or N.M for failure M in group N. Example: 1.2 refers to the 2nd failure in the 1st test class.

Important: Index assignment depends on iteration order of the provided map. Callers must pass a LinkedHashMap or TreeMap to guarantee stable indexes across runs. Passing a HashMap will cause --index=N to refer to different classes unpredictably.

Since:
1.0
Author:
Erik C. Thauvin
  • Method Details

    • getFailuresByIndex

      public static TestClassFailures getFailuresByIndex(Map<String,TestClassFailures> groupedFailures, int index)
      Returns the TestClassFailures at the given 0-based index.

      Assumes groupedFailures iteration order is stable. Use LinkedHashMap or TreeMap to guarantee consistent index assignment across runs.

      Parameters:
      groupedFailures - a map of test class failures
      index - the 0-based index
      Returns:
      the TestClassFailures at the specified index
      Throws:
      NullPointerException - if the map is null
      IllegalArgumentException - if the map is empty
      IndexOutOfBoundsException - if the index is out of bounds
    • hasIndex

      public static boolean hasIndex(@Nullable String arg, @Nullable Map<String,TestClassFailures> groupedFailures)
      Checks whether the given index string refers to a valid test or failure.

      Accepts groupIndex or groupIndex.failureIndex in 1-based form.

      Parameters:
      arg - a string representing 1-based indices, e.g. "1" or "1.2"
      groupedFailures - a map of test class failures
      Returns:
      true if the index is valid, false otherwise
    • indent

      public static String indent(String text, int indentSize)
      Indents each line of the input text by the specified number of spaces. Blank lines are not indented.
      Parameters:
      text - the input text; may be null or empty
      indentSize - the number of spaces to indent each line
      Returns:
      the indented text, or empty string if input is null/empty
      Throws:
      IllegalArgumentException - if indentSize is negative
    • indent

      public static String indent(String text)
      Indents each line of the input text by 8 spaces.
      Parameters:
      text - the input text
      Returns:
      the indented text with each line prefixed by 8 spaces
    • printDetails

      public static void printDetails(String arg, Map<String,TestClassFailures> groupedFailures)
      Prints the details of test failures based on 1-based CLI argument.

      Accepts groupIndex or groupIndex.failureIndex. Converts 1-based input to 0-based internally.

      Parameters:
      arg - a string representing 1-based indices, e.g. "1" or "1.2"
      groupedFailures - a map of test class failures
      Throws:
      IllegalArgumentException - if the index format is invalid
      IndexOutOfBoundsException - if the specified indices are out of bounds
      NumberFormatException - if the numeric portion cannot be parsed
    • printFailure

      public static void printFailure(TestFailure failure, @Nullable Integer groupIndex, @Nullable Integer failureIndex)
      Prints details of a single test failure with optional indices.
      Parameters:
      failure - the TestFailure to print
      groupIndex - the 0-based group index, or null
      failureIndex - the 0-based failure index, or null
    • printFailureWithStackTrace

      public static void printFailureWithStackTrace(TestFailure failure, int groupIndex, int failureIndex)
      Prints failure details with header and stack trace using 0-based indices.
      Parameters:
      failure - the TestFailure to print
      groupIndex - the 0-based group index
      failureIndex - the 0-based failure index
    • printFailures

      public static void printFailures(TestClassFailures failures, int groupIndex)
      Prints all failures for a test class using 0-based group index.
      Parameters:
      failures - the TestClassFailures to print
      groupIndex - the 0-based group index
    • printHeader

      public static void printHeader(String title)
      Prints a header with the specified title.
      Parameters:
      title - the title to print
    • printStackTrace

      public static void printStackTrace(TestFailure failure)
      Prints the stack trace of the provided test failure, if available.
      Parameters:
      failure - the TestFailure containing the stack trace
    • printSummary

      public static void printSummary(Map<String,TestClassFailures> groupedFailures)
      Prints a summary of JUnit test failures grouped by test class.
      Parameters:
      groupedFailures - a map of test class failures