Class LogCaptureRule
- java.lang.Object
-
- org.opendaylight.infrautils.testutils.LogCaptureRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public class LogCaptureRule extends Object implements org.junit.rules.TestRule
JUnit Rule which "captures" slf4j-simple logs. By default, it fails the test if an error was logged. It can also pass the test if a logged error was expected (but fail it otherwise).Usage:
public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule(); @Test ... logRule.expectError();See also e.g. slf4j-test or slf4jtesting (both of which, contrary to this, don't integrate with slf4j-simple which we already widely use in ODL tests).
- Author:
- Michael Vorburger.ch
- See Also:
ExpectedException
-
-
Constructor Summary
Constructors Constructor Description LogCaptureRule()
-
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)voidexpectError(String message)voidexpectError(String message, int howManyMessagesBack)voidexpectLastErrorMessageContains(String partialErrorMessage)ThrowablegetErrorThrowable(int howManyMessagesBack)ThrowablegetLastErrorThrowable()voidhandleErrorLogs(Consumer<com.google.common.collect.ImmutableList<LogCapture>> newErrorLogHandler)
-
-
-
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
-
handleErrorLogs
public void handleErrorLogs(Consumer<com.google.common.collect.ImmutableList<LogCapture>> newErrorLogHandler)
-
expectLastErrorMessageContains
public void expectLastErrorMessageContains(String partialErrorMessage)
-
expectError
public void expectError(String message, int howManyMessagesBack)
-
expectError
public void expectError(String message)
-
getLastErrorThrowable
public Throwable getLastErrorThrowable()
-
getErrorThrowable
public Throwable getErrorThrowable(int howManyMessagesBack)
-
-