Class MockLogAppender


  • public abstract class MockLogAppender
    extends Object

    MockLogAppender class. If you do not specify the log level specifically, the level will default to DEBUG. You can control the level by using the setupLogging(boolean, String) or setupLogging(boolean, String, Properties) methods.

    Used in unit tests to check that the level of logging produced by a test was suitable. In some cases, the test will be that no messages were logged at a higher priority than specified, e.g. Error messages logged when only Notice were expected. Some other tests may wish to ensure that an Error or Warn message was indeed logged as expected Remember: "Greater" in regards to level relates to priority; the higher the level, the less should usually be logged (e.g. Errors (highest) should be only the highest priority messages about really bad things, as compared to Debug (lowest) which is any old rubbish that might be interesting to a developer)
    Version:
    $Id: $
    Author:
    brozow
    • Field Detail

      • DEFAULT_LOG_LEVEL

        public static final String DEFAULT_LOG_LEVEL
    • Constructor Detail

      • MockLogAppender

        public MockLogAppender()
    • Method Detail

      • resetState

        public static void resetState()

        resetEvents

      • getEvents

        public static LoggingEvent[] getEvents()

        getEvents

      • getEventsGreaterOrEqual

        public static LoggingEvent[] getEventsGreaterOrEqual​(Level level)

        getEventsGreaterOrEqual

      • getEventsAtLevel

        public static LoggingEvent[] getEventsAtLevel​(Level level)

        getEventsAtLevel

        Returns events that were logged at the specified level
      • setupLogging

        public static void setupLogging()

        setupLogging

      • setupLogging

        public static void setupLogging​(Properties config)

        setupLogging

        Parameters:
        config - a Properties object.
      • setupLogging

        public static void setupLogging​(boolean toConsole)

        setupLogging

        Parameters:
        toConsole - a boolean.
      • setupLogging

        public static void setupLogging​(boolean toConsole,
                                        Properties props)

        setupLogging

        Parameters:
        toConsole - a boolean.
        props - a Properties object.
      • setupLogging

        public static void setupLogging​(boolean toConsole,
                                        String level)

        setupLogging

        Parameters:
        toConsole - a boolean.
        level - a String object.
      • setupLogging

        public static void setupLogging​(boolean toConsole,
                                        String level,
                                        Properties config)

        setupLogging

        Parameters:
        toConsole - a boolean.
        level - a String object.
        config - a Properties object.
      • noWarningsOrHigherLogged

        public static boolean noWarningsOrHigherLogged()

        noWarningsOrHigherLogged

        Returns:
        a boolean.
      • assertNotGreaterOrEqual

        public static void assertNotGreaterOrEqual​(Level level)
                                            throws junit.framework.AssertionFailedError

        assertNotGreaterOrEqual

        Throws:
        junit.framework.AssertionFailedError - if any.
      • assertNoWarningsOrGreater

        public static void assertNoWarningsOrGreater()
                                              throws junit.framework.AssertionFailedError

        assertNoWarningsOrGreater

        Throws:
        junit.framework.AssertionFailedError - if any.
      • assertNoErrorOrGreater

        public static void assertNoErrorOrGreater()
                                           throws junit.framework.AssertionFailedError
        Throws:
        junit.framework.AssertionFailedError
      • assertNoFatalOrGreater

        public static void assertNoFatalOrGreater()
                                           throws junit.framework.AssertionFailedError
        Throws:
        junit.framework.AssertionFailedError
      • assertLogAtLevel

        public static void assertLogAtLevel​(Level level)
                                     throws junit.framework.AssertionFailedError

        assertLogAtLevel

        Asserts that a message was logged at the requested level. Useful for testing code that *should* have logged an error message (or a notice or some other special case)
        Throws:
        junit.framework.AssertionFailedError - if any.
      • addEvent

        public static void addEvent​(LoggingEvent loggingEvent)
      • assertNoLogging

        public static void assertNoLogging()
                                    throws junit.framework.AssertionFailedError
        Throws:
        junit.framework.AssertionFailedError
      • assertLogMatched

        public static void assertLogMatched​(Level level,
                                            String message)
      • assertNoLogMatched

        public static void assertNoLogMatched​(Level level,
                                              String message)