Skip to content

Instantly share code, notes, and snippets.

@ivanursul
Created April 1, 2015 15:17
Show Gist options
  • Select an option

  • Save ivanursul/15a96f98ddf4ecb01fd1 to your computer and use it in GitHub Desktop.

Select an option

Save ivanursul/15a96f98ddf4ecb01fd1 to your computer and use it in GitHub Desktop.
LoggingRule.java for www.ivanursul.com
package org.ivanursul.investigration.rule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class LoggingRule implements TestRule {
private String name;
public class LoggingStatement extends Statement {
private final Statement statement;
public LoggingStatement(final Statement statement) {
this.statement = statement;
}
@Override
public void evaluate() throws Throwable {
System.out.println("before: " + name);
statement.evaluate();
System.out.println("after: " + name);
}
}
public LoggingRule(final String name) {
super();
this.name = name;
}
@Override
public Statement apply(final Statement base, final Description description) {
return new LoggingStatement(base);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment