Home | History | Annotate | Download | only in rules
      1 package org.junit.rules;
      2 
      3 import org.junit.runner.Description;
      4 import org.junit.runners.model.Statement;
      5 
      6 /**
      7  * Runs a collection of rules on a statement.
      8  */
      9 public class RunRules extends Statement {
     10 	private final Statement statement;
     11 
     12 	public RunRules(Statement base, Iterable<TestRule> rules, Description description) {
     13 		statement= applyAll(base, rules, description);
     14 	}
     15 
     16 	@Override
     17 	public void evaluate() throws Throwable {
     18 		statement.evaluate();
     19 	}
     20 
     21 	private static Statement applyAll(Statement result, Iterable<TestRule> rules,
     22 			Description description) {
     23 		for (TestRule each : rules)
     24 			result= each.apply(result, description);
     25 		return result;
     26 	}
     27 }
     28