com.atlassian.plugin.test
Class CapturedLogging

java.lang.Object
  extended by org.junit.rules.ExternalResource
      extended by com.atlassian.plugin.test.CapturedLogging
All Implemented Interfaces:
org.junit.rules.TestRule

public class CapturedLogging
extends org.junit.rules.ExternalResource

A JUnit Rule for capturing and verifying log messages from a given class. This implementation is Log4J specific, but the interface is framed in SLF4J terminology. The intent is that if we need to switch to a different logger we should be able to preserve the interface, since it mirrors the SLF4J interface used by non test code. The implementation uses a Log4j appender to capture log messages for verification.

Since:
3.2.16

Constructor Summary
CapturedLogging(Class logSource)
           
 
Method Summary
protected  void after()
           
protected  void before()
           
static org.hamcrest.Matcher<CapturedLogging> didLog(org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> loggingEventMatcher)
           
static org.hamcrest.Matcher<CapturedLogging> didLogDebug(org.hamcrest.Matcher<String> messageMatcher)
           
static org.hamcrest.Matcher<CapturedLogging> didLogDebug(String... substrings)
           
static org.hamcrest.Matcher<CapturedLogging> didLogWarn(org.hamcrest.Matcher<String> messageMatcher)
           
static org.hamcrest.Matcher<CapturedLogging> didLogWarn(String... substrings)
           
 List<org.apache.log4j.spi.LoggingEvent> getLoggingEvents()
           
static org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> levelAndMessageMatch(org.apache.log4j.Level level, org.hamcrest.Matcher<String> messageMatcher)
           
static org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> levelIs(org.apache.log4j.Level level)
           
static org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> messageMatches(org.hamcrest.Matcher<String> stringMatcher)
           
 String toString()
           
 
Methods inherited from class org.junit.rules.ExternalResource
apply
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CapturedLogging

public CapturedLogging(Class logSource)
Method Detail

getLoggingEvents

public List<org.apache.log4j.spi.LoggingEvent> getLoggingEvents()

before

protected void before()
               throws Throwable
Overrides:
before in class org.junit.rules.ExternalResource
Throws:
Throwable

after

protected void after()
Overrides:
after in class org.junit.rules.ExternalResource

didLog

public static org.hamcrest.Matcher<CapturedLogging> didLog(org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> loggingEventMatcher)

didLogWarn

public static org.hamcrest.Matcher<CapturedLogging> didLogWarn(org.hamcrest.Matcher<String> messageMatcher)

didLogWarn

public static org.hamcrest.Matcher<CapturedLogging> didLogWarn(String... substrings)

didLogDebug

public static org.hamcrest.Matcher<CapturedLogging> didLogDebug(org.hamcrest.Matcher<String> messageMatcher)

didLogDebug

public static org.hamcrest.Matcher<CapturedLogging> didLogDebug(String... substrings)

levelIs

public static org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> levelIs(org.apache.log4j.Level level)

messageMatches

public static org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> messageMatches(org.hamcrest.Matcher<String> stringMatcher)

toString

public String toString()
Overrides:
toString in class Object

levelAndMessageMatch

public static org.hamcrest.Matcher<org.apache.log4j.spi.LoggingEvent> levelAndMessageMatch(org.apache.log4j.Level level,
                                                                                           org.hamcrest.Matcher<String> messageMatcher)


Copyright © 2015 Atlassian. All rights reserved.