com.github.valfirst.slf4jtest.TestLoggerFactoryResetRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of slf4j-test Show documentation
Show all versions of slf4j-test Show documentation
An in-memory SLF4J implementation focused on aiding unit testing.
package com.github.valfirst.slf4jtest;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* A JUnit rule that clears the ThreadLocal
* state of all the TestLoggers and the TestLoggerFactory.
*/
public class TestLoggerFactoryResetRule implements TestRule {
@Override
public Statement apply(final Statement base, final Description description) {
return new TestLoggerFactoryResettingStatement(base);
}
private static class TestLoggerFactoryResettingStatement extends Statement {
private final Statement base;
public TestLoggerFactoryResettingStatement(final Statement base) {
super();
this.base = base;
}
@Override
public void evaluate() throws Throwable {
TestLoggerFactory.clear();
try {
base.evaluate();
} finally {
TestLoggerFactory.clear();
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy