Class TestLoggerAssert

  • All Implemented Interfaces:
    org.assertj.core.api.Assert<TestLoggerAssert,​TestLogger>, org.assertj.core.api.Descriptable<TestLoggerAssert>, org.assertj.core.api.ExtensionPoints<TestLoggerAssert,​TestLogger>

    public class TestLoggerAssert
    extends org.assertj.core.api.AbstractAssert<C,​TestLogger>
    A set of assertions to validate that logs have been logged to a TestLogger.

    Should be thread safe, as this uses testLogger.getLoggingEvents() by default. The assertion mode can be switched to use testLogger.getAllLoggingEvents() by calling anyThread().

    • Constructor Detail

      • TestLoggerAssert

        protected TestLoggerAssert​(TestLogger testLogger)
    • Method Detail

      • anyThread

        public TestLoggerAssert anyThread()
        Changes the assertion mode to verify that log messages have been logged regardless of which thread actually logged the message.
        Returns:
        a TestLoggerAssert for chaining
      • hasLogged

        public TestLoggerAssert hasLogged​(Level level,
                                          String message,
                                          Object... arguments)
        Verify that a log message, at a specific level, has been logged by the test logger.
        Parameters:
        level - the level of the log message to look for
        message - the expected message
        arguments - any optional arguments that may be provided to the log message
        Returns:
        a TestLoggerAssert for chaining
      • hasLogged

        public TestLoggerAssert hasLogged​(Throwable throwable,
                                          Level level,
                                          String message,
                                          Object... arguments)
        Verify that a log message, at a specific level, has been logged by the test logger in the presence of a Throwable.
        Parameters:
        throwable - the throwable that is attached to the log message
        level - the level of the log message to look for
        message - the expected message
        arguments - any optional arguments that may be provided to the log message
        Returns:
        a TestLoggerAssert for chaining
      • hasNotLogged

        public TestLoggerAssert hasNotLogged​(Level level,
                                             String message,
                                             Object... arguments)
        Verify that a log message, at a specific level, has not been logged by the test logger.
        Parameters:
        level - the level of the log message to look for
        message - the expected message
        arguments - any optional arguments that may be provided to the log message
        Returns:
        a TestLoggerAssert for chaining
      • hasNotLogged

        public TestLoggerAssert hasNotLogged​(Throwable throwable,
                                             Level level,
                                             String message,
                                             Object... arguments)
        Verify that a log message, at a specific level, has not been logged by the test logger in the presence of a Throwable.
        Parameters:
        throwable - the throwable that is attached to the log message
        level - the level of the log message to look for
        message - the expected message
        arguments - any optional arguments that may be provided to the log message
        Returns:
        a TestLoggerAssert for chaining