public LoggingEvent removeFirst() { if (hasEvents()) { ++lineNumber; return this.events.removeFirst(); } return null; }
String expectedMessageExpression, Class<? extends Throwable> expectedExceptionClass ) { if (!hasEvents()) { fail("Expected log message but found none: " + expectedLevel + " - " + expectedMessageExpression);
@Test public void shouldLogNoMessagesIfLog4jSetToOffLevel() { log4jLogger.setLevel(Level.OFF); logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); assertEquals(false, log.hasEvents()); }
@Test public void shouldAcceptMessageAndNullThrowable() { Throwable t = null; logger.error(t, errorMessageWithNullException); logger.warn(t, warningMessageWithNullException); logger.info(t, infoMessageWithNullException); logger.debug(t, "This is a debug message with a null exception"); logger.trace(t, "This is a trace message with a null exception"); log.removeFirst(Logger.Level.ERROR, "This is an error message with a null exception"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with a null exception"); log.removeFirst(Logger.Level.INFO, "This is an info message with a null exception"); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with a null exception"); log.removeFirst(Logger.Level.TRACE, "This is a trace message with a null exception"); assertEquals(false, log.hasEvents()); }
@Test public void shouldLogAppropriateMessagesIfLog4jSetToTraceLevel() { log4jLogger.setLevel(Level.TRACE); logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); log.removeFirst(Logger.Level.ERROR, "This is an error message with no parameters"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with no parameters"); log.removeFirst(Logger.Level.INFO, "This is an info message with no parameters"); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with no parameters"); log.removeFirst(Logger.Level.TRACE, "This is a trace message with no parameters"); assertEquals(false, log.hasEvents()); }
@Test public void shouldLogAppropriateMessagesIfSetToAllLevel() { log4jLogger.setLevel(Level.ALL); logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); log.removeFirst(Logger.Level.ERROR, "This is an error message with no parameters"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with no parameters"); log.removeFirst(Logger.Level.INFO, "This is an info message with no parameters"); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with no parameters"); log.removeFirst(Logger.Level.TRACE, "This is a trace message with no parameters"); assertEquals(false, log.hasEvents()); }
@Test public void shouldAcceptMessageAndThrowable() { Throwable t = new RuntimeException("This is the runtime exception message"); logger.error(t, errorMessageWithException); logger.warn(t, warningMessageWithException); logger.info(t, infoMessageWithException); logger.debug(t, "This is a debug message with an exception"); logger.trace(t, "This is a trace message with an exception"); log.removeFirst(Logger.Level.ERROR, "This is an error message with an exception", RuntimeException.class); log.removeFirst(Logger.Level.WARNING, "This is a warning message with an exception", RuntimeException.class); log.removeFirst(Logger.Level.INFO, "This is an info message with an exception", RuntimeException.class); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with an exception", RuntimeException.class); log.removeFirst(Logger.Level.TRACE, "This is a trace message with an exception", RuntimeException.class); assertEquals(false, log.hasEvents()); }
@Test public void shouldNotAcceptMessageWithNonNullAndNullParameters() { logger.error(errorMessageWithTwoParameters, "first", null); logger.warn(warningMessageWithTwoParameters, "first", null); logger.info(infoMessageWithTwoParameters, "first", null); logger.debug("This is a debug message with a {0} parameter and the {1} parameter", "first", null); logger.trace("This is a trace message with a {0} parameter and the {1} parameter", "first", null); log.removeFirst(Logger.Level.ERROR, "This is an error message with a first parameter and the null parameter"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with a first parameter and the null parameter"); log.removeFirst(Logger.Level.INFO, "This is an info message with a first parameter and the null parameter"); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with a first parameter and the null parameter"); log.removeFirst(Logger.Level.TRACE, "This is a trace message with a first parameter and the null parameter"); assertEquals(false, log.hasEvents()); }
@Test public void shouldAcceptNullMessageAndThrowable() { Throwable t = new RuntimeException("This is the runtime exception message in LoggerTest"); logger.error(t, null); logger.warn(t, null); logger.info(t, null); logger.debug(t, null); logger.trace(t, null); log.removeFirst(Logger.Level.ERROR, null, RuntimeException.class); log.removeFirst(Logger.Level.WARNING, null, RuntimeException.class); log.removeFirst(Logger.Level.INFO, null, RuntimeException.class); log.removeFirst(Logger.Level.DEBUG, null, RuntimeException.class); log.removeFirst(Logger.Level.TRACE, null, RuntimeException.class); assertEquals(false, log.hasEvents()); }
@Test public void shouldAcceptMessageWithNoParameters() { logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); log.removeFirst(Logger.Level.ERROR, "This is an error message with no parameters"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with no parameters"); log.removeFirst(Logger.Level.INFO, "This is an info message with no parameters"); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with no parameters"); log.removeFirst(Logger.Level.TRACE, "This is a trace message with no parameters"); assertEquals(false, log.hasEvents()); }
@Test public void shouldAcceptMessageWithObjectAndPrimitiveParameters() { logger.error(errorMessageWithTwoParameters, "first", 2); logger.warn(warningMessageWithTwoParameters, "first", 2); logger.info(infoMessageWithTwoParameters, "first", 2); logger.debug("This is a debug message with a {0} parameter and the {1} parameter", "first", 2); logger.trace("This is a trace message with a {0} parameter and the {1} parameter", "first", 2); log.removeFirst(Logger.Level.ERROR, "This is an error message with a first parameter and the 2 parameter"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with a first parameter and the 2 parameter"); log.removeFirst(Logger.Level.INFO, "This is an info message with a first parameter and the 2 parameter"); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with a first parameter and the 2 parameter"); log.removeFirst(Logger.Level.TRACE, "This is a trace message with a first parameter and the 2 parameter"); assertEquals(false, log.hasEvents()); }
@Test public void shouldLogAppropriateMessagesIfLog4jSetToDebugLevel() { log4jLogger.setLevel(Level.DEBUG); logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); log.removeFirst(Logger.Level.ERROR, "This is an error message with no parameters"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with no parameters"); log.removeFirst(Logger.Level.INFO, "This is an info message with no parameters"); log.removeFirst(Logger.Level.DEBUG, "This is a debug message with no parameters"); assertEquals(false, log.hasEvents()); }
public void shouldQuietlyAcceptNullMessage() { logger.error(null); logger.warn(null); logger.info(null); logger.debug(null); logger.trace(null); assertEquals(false, log.hasEvents()); }
@Test public void shouldLogAppropriateMessagesIfLog4jSetToWarningLevel() { log4jLogger.setLevel(Level.WARN); logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); log.removeFirst(Logger.Level.ERROR, "This is an error message with no parameters"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with no parameters"); assertEquals(false, log.hasEvents()); }
@Test public void shouldLogAppropriateMessagesIfLog4jSetToInfoLevel() { log4jLogger.setLevel(Level.INFO); logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); log.removeFirst(Logger.Level.ERROR, "This is an error message with no parameters"); log.removeFirst(Logger.Level.WARNING, "This is a warning message with no parameters"); log.removeFirst(Logger.Level.INFO, "This is an info message with no parameters"); assertEquals(false, log.hasEvents()); }
@Test public void shouldLogAppropriateMessagesIfLog4jSetToErrorLevel() { log4jLogger.setLevel(Level.ERROR); logger.error(errorMessageWithNoParameters); logger.warn(warningMessageWithNoParameters); logger.info(infoMessageWithNoParameters); logger.debug("This is a debug message with no parameters"); logger.trace("This is a trace message with no parameters"); log.removeFirst(Logger.Level.ERROR, "This is an error message with no parameters"); assertEquals(false, log.hasEvents()); }