Skip to content

Instantly share code, notes, and snippets.

@garyfleming
Created June 2, 2011 19:44
Show Gist options
  • Save garyfleming/1005137 to your computer and use it in GitHub Desktop.
Save garyfleming/1005137 to your computer and use it in GitHub Desktop.
JUnit RepeatRule.java
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
public class RepeatRule implements MethodRule {
private int times;
public RepeatRule(int times) {
this.times = times;
}
@Override
public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
for (int i = 0; i < times; i++) {
base.evaluate();
}
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment