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  * @since 4.9
10  */
11 public class RunRules extends Statement {
12     private final Statement statement;
13 
RunRules(Statement base, Iterable<TestRule> rules, Description description)14     public RunRules(Statement base, Iterable<TestRule> rules, Description description) {
15         statement = applyAll(base, rules, description);
16     }
17 
18     @Override
evaluate()19     public void evaluate() throws Throwable {
20         statement.evaluate();
21     }
22 
applyAll(Statement result, Iterable<TestRule> rules, Description description)23     private static Statement applyAll(Statement result, Iterable<TestRule> rules,
24             Description description) {
25         for (TestRule each : rules) {
26             result = each.apply(result, description);
27         }
28         return result;
29     }
30 }
31