Class CapturingErrorReportPublisher

java.lang.Object
com.tnsai.observability.errors.CapturingErrorReportPublisher
All Implemented Interfaces:
ErrorReportPublisher

public final class CapturingErrorReportPublisher extends Object implements ErrorReportPublisher
In-memory ErrorReportPublisher for tests. Holds every published report in insertion order; assertions can drain or filter.

Not registered via SPI — must be wired explicitly via ErrorReports.setPublisher(ErrorReportPublisher) in the test's setUp / @BeforeEach, and torn down in @AfterEach. Tests that forget the teardown leak captured reports across methods.

Thread-safety: backed by a CopyOnWriteArrayList so concurrent publish(ErrorReport) and

invalid reference
#drain()
don't blow up. Reads see a snapshot at the moment of iteration.
Since:
0.5.0 (issue #86)
  • Constructor Details

    • CapturingErrorReportPublisher

      public CapturingErrorReportPublisher()
  • Method Details

    • publish

      public void publish(ErrorReport report)
      Description copied from interface: ErrorReportPublisher
      Publish a single error report. Errors during publication must not propagate to the caller — the caller is already in an error path; an exception here would mask the original failure.
      Specified by:
      publish in interface ErrorReportPublisher
    • captured

      public List<ErrorReport> captured()
      Immutable snapshot of every captured report so far.
    • size

      public int size()
      Number of reports captured so far.
    • last

      public ErrorReport last()
      Last captured report, or null if none.
    • matching

      public List<ErrorReport> matching(Predicate<ErrorReport> filter)
      Reports matching a predicate (e.g. by fingerprint or category).
    • clear

      public void clear()
      Empties the buffer. Use between test cases for isolation.