下面列出了怎么用org.junit.rules.RunRules的API类实例代码及写法,或者点击链接到github查看源代码。
private Statement withRules(EndToEndTestDescriptor child, Object target, Statement statement) {
// We do not support MethodRules like the JUnit runner does as it has been functionally
// replaced by TestRules (https://junit.org/junit4/javadoc/4.12/org/junit/rules/MethodRule.html)
List<TestRule> testRules =
getTestClass().getAnnotatedMethodValues(target, Rule.class, TestRule.class);
testRules.addAll(getTestClass().getAnnotatedFieldValues(target, Rule.class, TestRule.class));
return testRules.isEmpty()
? statement
: new RunRules(statement, testRules, describeChild(child));
}
/**
* @see org.junit.runners.BlockJUnit4ClassRunner#withTestRules(FrameworkMethod, List, Statement)
*/
private Statement withTestRules( FrameworkMethod method, List<TestRule> testRules, Statement statement )
{
return testRules.isEmpty() ? statement : new RunRules( statement, testRules, describeChild( method ) );
}
private Statement withTestRules(final List<TestRule> testRules, final Statement statement,
final Description childDescription) {
return testRules.isEmpty() ? statement : new RunRules(statement, testRules, childDescription);
}
private synchronized Statement withClassRules(final Statement base,
final Description description) {
List<TestRule> classRules = getClassRules();
return classRules.isEmpty() ? base : new RunRules(base, classRules, description);
}
private Statement withClassRules(Statement statement) {
List<TestRule> classRules = classRules();
return classRules.isEmpty() ? statement :
new RunRules(statement, classRules, getDescription());
}
/**
* Returns a Statement.
*
* @param statement The base statement
* @return a RunRules statement if any class-level Rule are found, or the base statement
*/
private Statement withTestRules(final FrameworkMethod method, final Object target, final Statement statement) {
final List<TestRule> testRules = getTestRules(target);
return testRules.isEmpty() ? statement : new RunRules(statement, testRules, describeChild(method));
}
/**
* Returns a {@link org.junit.runners.model.Statement}: apply all
* static fields assignable to {@link org.junit.rules.TestRule}
* annotated with {@link org.junit.ClassRule}.
*
* @param statement the base statement
* @return a RunRules statement if any class-level {@link org.junit.Rule}s are
* found, or the base statement
*/
private Statement withClassRules(Statement statement) {
List<TestRule> classRules = classRules();
return classRules.isEmpty() ? statement :
new RunRules(statement, classRules, getDescription());
}
/**
* Returns a {@link org.junit.runners.model.Statement}: apply all non-static value fields
* annotated with {@link org.junit.Rule}.
*
* @param statement The base statement
* @return a RunRules statement if any class-level {@link org.junit.Rule}s are
* found, or the base statement
*/
private Statement withTestRules(FrameworkMethod method, List<TestRule> testRules,
Statement statement) {
return testRules.isEmpty() ? statement :
new RunRules(statement, testRules, describeChild(method));
}