com.codereligion.cherry.junit.logback
Class LogRecorder

java.lang.Object
  extended by com.codereligion.cherry.junit.logback.LogRecorder
All Implemented Interfaces:
org.junit.rules.TestRule

public class LogRecorder
extends Object
implements org.junit.rules.TestRule

JUnit rule which records all events emitted by the loggers specified in the given LogSpec at the specified log level.

Since:
17.03.2015
Author:
Sebastian Gröbler

Method Summary
 org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
           
 ch.qos.logback.classic.spi.ILoggingEvent event()
          Returns the first event recorded during the test execution, or throws an AssertionError, in case no event was recorded.
 List<ch.qos.logback.classic.spi.ILoggingEvent> events()
          Returns all events recorded during the test execution in the order they were logged.
static LogRecorder expectedLogs(LogSpec... logSpecs)
          Creates a log recorder rule which records events for all logs specified by the given LogSpec.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

expectedLogs

public static LogRecorder expectedLogs(LogSpec... logSpecs)
Creates a log recorder rule which records events for all logs specified by the given LogSpec. If the same logger is specified multiple times with a different log level, then the last spec wins.

Parameters:
logSpecs - the to be expected logs
Returns:
a new LogRecorder

apply

public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
                                               org.junit.runner.Description description)
Specified by:
apply in interface org.junit.rules.TestRule

events

public List<ch.qos.logback.classic.spi.ILoggingEvent> events()
Returns all events recorded during the test execution in the order they were logged.

Returns:
all recorded events

event

public ch.qos.logback.classic.spi.ILoggingEvent event()
Returns the first event recorded during the test execution, or throws an AssertionError, in case no event was recorded.

Returns:
the first recorded event
Throws:
AssertionError - when no event was recorded


Copyright © 2015. All rights reserved.