Class LogbackCaptureTestExtension

java.lang.Object
ca.uhn.test.util.LogbackCaptureTestExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

public class LogbackCaptureTestExtension extends Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
Test helper to collect logback lines. The empty constructor will capture all log events, or you can name a log root to limit the noise.
  • Constructor Details

    • LogbackCaptureTestExtension

      public LogbackCaptureTestExtension(ch.qos.logback.classic.Logger theLogger)
      Parameters:
      theLogger - the log to capture
    • LogbackCaptureTestExtension

      public LogbackCaptureTestExtension(ch.qos.logback.classic.Logger theLogger, ch.qos.logback.classic.Level theTestLogLevel)
      Parameters:
      theLogger - the log to capture
      theTestLogLevel - the log Level to set on the target logger for the duration of the test
    • LogbackCaptureTestExtension

      public LogbackCaptureTestExtension(String theLoggerName)
      Parameters:
      theLoggerName - the log name to capture
    • LogbackCaptureTestExtension

      Capture the root logger - all lines.
    • LogbackCaptureTestExtension

      public LogbackCaptureTestExtension(String theLoggerName, ch.qos.logback.classic.Level theLevel)
  • Method Details

    • getLogEvents

      public List<ch.qos.logback.classic.spi.ILoggingEvent> getLogEvents()
      Returns a copy to avoid concurrent modification errors.
      Returns:
      A copy of the log events so far.
    • clearEvents

      public void clearEvents()
      Clear accumulated log events.
    • getAppender

      public ch.qos.logback.core.read.ListAppender<ch.qos.logback.classic.spi.ILoggingEvent> getAppender()
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      Throws:
      Exception
    • setUp

      public void setUp()
      Guts of beforeEach exposed for manual lifecycle.
    • afterEach

      public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
      Throws:
      Exception
    • filterLoggingEventsWithMessageEqualTo

      public List<ch.qos.logback.classic.spi.ILoggingEvent> filterLoggingEventsWithMessageEqualTo(String theMessageText)
    • filterLoggingEventsWithMessageContaining

      public List<ch.qos.logback.classic.spi.ILoggingEvent> filterLoggingEventsWithMessageContaining(String theMessageText)
    • filterLoggingEventsWithPredicate

      public List<ch.qos.logback.classic.spi.ILoggingEvent> filterLoggingEventsWithPredicate(Predicate<ch.qos.logback.classic.spi.ILoggingEvent> theLoggingEventPredicate)
    • eventWithLevelAndMessageContains

      public static org.hamcrest.Matcher<ch.qos.logback.classic.spi.ILoggingEvent> eventWithLevelAndMessageContains(@Nonnull ch.qos.logback.classic.Level theLevel, @Nonnull String thePartialMessage)
    • eventWithLevel

      public static org.hamcrest.Matcher<ch.qos.logback.classic.spi.ILoggingEvent> eventWithLevel(@Nonnull ch.qos.logback.classic.Level theLevel)
    • eventWithMessageContains

      public static org.hamcrest.Matcher<ch.qos.logback.classic.spi.ILoggingEvent> eventWithMessageContains(@Nonnull String thePartialMessage)