org.junit.rules
Class RuleChain

java.lang.Object
  extended by org.junit.rules.RuleChain
All Implemented Interfaces:
TestRule

Deprecated. Since 4.13 ordering of rules can be naturally specified with an annotation attribute.

@Deprecated
public class RuleChain
extends Object
implements TestRule

The RuleChain rule allows ordering of TestRules. You create a RuleChain with outerRule(TestRule) and subsequent calls of around(TestRule):

 public 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
 
RuleChain cannot be used to define the order of existing rules. For example in the below snippet the LoggingRule middle would be executed outside as well as inside the RuleChain:
 @Rule
 public LoggingRule middle = new LoggingRule("middle rule");
 
 @Rule
 public RuleChain chain = RuleChain
                          .outerRule(new LoggingRule("outer rule"))
                          .around(middle)
                          .around(new LoggingRule("inner rule"));
 

Since:
4.10
See Also:
Rule.order(), ClassRule.order()

Method Summary
 Statement apply(Statement base, Description description)
          Deprecated. Modifies the method-running Statement to implement this test-running rule.
 RuleChain around(TestRule enclosedRule)
          Deprecated. Create a new RuleChain, which encloses the given TestRule with the rules of the current RuleChain.
static RuleChain emptyRuleChain()
          Deprecated. Returns a RuleChain without a TestRule.
static RuleChain outerRule(TestRule outerRule)
          Deprecated. Returns a RuleChain with a single TestRule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

emptyRuleChain

public static RuleChain emptyRuleChain()
Deprecated. 
Returns a RuleChain without a TestRule. This method may be the starting point of a RuleChain.

Returns:
a RuleChain without a TestRule.

outerRule

public static RuleChain outerRule(TestRule outerRule)
Deprecated. 
Returns a RuleChain with a single TestRule. This method is the usual starting point of a RuleChain.

Parameters:
outerRule - the outer rule of the RuleChain.
Returns:
a RuleChain with a single TestRule.

around

public RuleChain around(TestRule enclosedRule)
Deprecated. 
Create a new RuleChain, which encloses the given TestRule with the rules of the current RuleChain.

Parameters:
enclosedRule - the rule to enclose; must not be null.
Returns:
a new RuleChain.
Throws:
NullPointerException - if the argument enclosedRule is null

apply

public Statement apply(Statement base,
                       Description description)
Deprecated. 
Modifies the method-running Statement to implement this test-running rule.

Specified by:
apply in interface TestRule
Parameters:
base - The Statement to be modified
description - A Description of the test implemented in base
Returns:
a new statement, which may be the same as base, a wrapper around base, or a completely new Statement.


Copyright © 2002–2018 JUnit. All rights reserved.