Package org.xwiki.test
Class LogRule
- java.lang.Object
-
- org.xwiki.test.LogRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
@Deprecated public class LogRule extends Object implements org.junit.rules.TestRule
Deprecated.starting with 7.0M1 you should useAllLogRule
instead since we want tests to not output anything to the consoleAllow capturing Logs output in the Class under test during unit testing. 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 LogRule logRule = new LogRule() {{ record(LogLevel.WARN); recordLoggingForType(RestrictParseLocationEventHandler.class); }};
- Since:
- 4.2RC1
- Version:
- $Id: 43bf6efed045d59d86f7ca694f2cca1de03c3a1f $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LogRule.LogLevel
Deprecated.Helper class to represent Logging levels to capture.class
LogRule.LogStatement
Deprecated.The actual code that executes our capturing logic before the test runs and removes it after it has run.
-
Constructor Summary
Constructors Constructor Description LogRule()
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement statement, org.junit.runner.Description description)
Deprecated.boolean
contains(String logOutput)
Deprecated.org.slf4j.Marker
getMarker(int position)
Deprecated.String
getMessage(int position)
Deprecated.void
record(LogRule.LogLevel level)
Deprecated.void
recordLoggingForType(Class<?> type)
Deprecated.int
size()
Deprecated.
-
-
-
Method Detail
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement, org.junit.runner.Description description)
Deprecated.- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
record
public void record(LogRule.LogLevel level)
Deprecated.- Parameters:
level
- the log level to capture
-
recordLoggingForType
public void recordLoggingForType(Class<?> type)
Deprecated.- Parameters:
type
- the logging class type for which to capture logs
-
contains
public boolean contains(String logOutput)
Deprecated.- Parameters:
logOutput
- the log output to match in the captured data- Returns:
- true if the passed text was logged or false otherwise
-
getMessage
public String getMessage(int position)
Deprecated.- 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)
Deprecated.- 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()
Deprecated.- Returns:
- the number of log messages that have been captured
-
-