All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.org.lidalia.slf4jtest.TestLoggerFactoryResetRule Maven / Gradle / Ivy

package uk.org.lidalia.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 {
            try {
                base.evaluate();
            } finally {
                TestLoggerFactory.clear();
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy