public class RuleChain extends Object implements TestRule
RuleChain with outerRule(TestRule) and subsequent calls of
around(TestRule):
public static class UseRuleChain {
@Rule
public RuleChain chain= RuleChain
.outerRule(new LoggingRule("outer rule")
.around(new LoggingRule("middle rule")
.around(new LoggingRule("inner rule");
@Test
public void example() {
assertTrue(true);
}
}
writes the log
starting outer rule starting middle rule starting inner rule finished inner rule finished middle rule finished outer rule
| Modifier and Type | Method and Description |
|---|---|
Statement |
apply(Statement base,
Description description)
Modifies the method-running
Statement to implement this
test-running rule. |
RuleChain |
around(TestRule enclosedRule)
Create a new
RuleChain, which encloses the nextRule with
the rules of the current RuleChain. |
static RuleChain |
emptyRuleChain()
Returns a
RuleChain without a TestRule. |
static RuleChain |
outerRule(TestRule outerRule)
Returns a
RuleChain with a single TestRule. |
public static RuleChain outerRule(TestRule outerRule)
outerRule - the outer rule of the RuleChain.RuleChain with a single TestRule.public RuleChain around(TestRule enclosedRule)
RuleChain, which encloses the nextRule with
the rules of the current RuleChain.enclosedRule - the rule to enclose.RuleChain.public Statement apply(Statement base, Description description)
Statement to implement this
test-running rule.apply in interface TestRulebase - The Statement to be modifieddescription - A Description of the test implemented in basebase,
a wrapper around base, or a completely new Statement.