001package org.junit.rules;
002
003import org.junit.runner.Description;
004import org.junit.runners.model.Statement;
005
006/**
007 * Runs a collection of rules on a statement.
008 *
009 * @since 4.9
010 */
011public class RunRules extends Statement {
012    private final Statement statement;
013
014    public RunRules(Statement base, Iterable<TestRule> rules, Description description) {
015        statement = applyAll(base, rules, description);
016    }
017
018    @Override
019    public void evaluate() throws Throwable {
020        statement.evaluate();
021    }
022
023    private static Statement applyAll(Statement result, Iterable<TestRule> rules,
024            Description description) {
025        for (TestRule each : rules) {
026            result = each.apply(result, description);
027        }
028        return result;
029    }
030}