Package org.xwiki.test
Class AllLogRule
- java.lang.Object
-
- org.xwiki.test.AllLogRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public class AllLogRule extends Object implements org.junit.rules.TestRule
Allow capturing Logs output during the execution of the unit test. This is useful for two reasons:- it allows not outputting log messages in the console which is a bad practice. When a test run it should not output anything and if it needs to assert something, it has to be done in the test itself.
- it allows to assert the output log messages
Example usage:
@Rule public AllLogRule logRule = new AllLogRule();- Since:
- 7.0M1
- Version:
- $Id: 99cdd91537b4da77543a58f7fc7b4b222ad2c9cc $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAllLogRule.LogStatementThe actual code that executes our capturing logic before the test runs and removes it after it has run.
-
Constructor Summary
Constructors Constructor Description AllLogRule()Capture INFO log.AllLogRule(LogLevel level)Caputure passed log level.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statementapply(org.junit.runners.model.Statement statement, org.junit.runner.Description description)ch.qos.logback.classic.spi.ILoggingEventgetLogEvent(int position)org.slf4j.MarkergetMarker(int position)StringgetMessage(int position)voidignoreAllMessages()Voluntarily ignore all messages to signify they should not need to be asserted.voidignoreMessage(int position)Voluntarily ignore a message to signify it should not need to be asserted.intsize()
-
-
-
Constructor Detail
-
AllLogRule
public AllLogRule()
Capture INFO log.
-
AllLogRule
public AllLogRule(LogLevel level)
Caputure passed log level.- Parameters:
level- the level of log to capture
-
-
Method Detail
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement, org.junit.runner.Description description)- Specified by:
applyin interfaceorg.junit.rules.TestRule
-
getLogEvent
public ch.qos.logback.classic.spi.ILoggingEvent getLogEvent(int position)
- Parameters:
position- the message number in the list of captured logs- Returns:
- the logging event corresponding to the message, allowing to get information such as the level, the marker, the formatted string, etc
- Since:
- 10.4RC1
-
getMessage
public String getMessage(int position)
- Parameters:
position- the message number in the list of captured logs- Returns:
- the message at the specified position
-
getMarker
public org.slf4j.Marker getMarker(int position)
- Parameters:
position- the message number in the list of captured logs- Returns:
- the marker at the specified position
- Since:
- 7.0M2
-
size
public int size()
- Returns:
- the number of log messages that have been captured
-
ignoreAllMessages
public void ignoreAllMessages()
Voluntarily ignore all messages to signify they should not need to be asserted.- Since:
- 10.4RC1
-
ignoreMessage
public void ignoreMessage(int position)
Voluntarily ignore a message to signify it should not need to be asserted.- Parameters:
position- the message number in the list of captured logs- Since:
- 10.4RC1
-
-