use of org.junit.rules.MethodRule in project tomee by apache.
the class TomEEEmbeddedSingleRunner method rules.
@Override
protected List<MethodRule> rules(final Object test) {
final List<MethodRule> rules = super.rules(test);
rules.add(new MethodRule() {
@Override
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
BASE.start(test);
BASE.composerInject(target);
base.evaluate();
}
};
}
});
return rules;
}
use of org.junit.rules.MethodRule in project junit4 by junit-team.
the class BlockJUnit4ClassRunner method withRules.
private Statement withRules(FrameworkMethod method, Object target, Statement statement) {
RuleContainer ruleContainer = new RuleContainer();
CURRENT_RULE_CONTAINER.set(ruleContainer);
try {
List<TestRule> testRules = getTestRules(target);
for (MethodRule each : rules(target)) {
if (!(each instanceof TestRule && testRules.contains(each))) {
ruleContainer.add(each);
}
}
for (TestRule rule : testRules) {
ruleContainer.add(rule);
}
} finally {
CURRENT_RULE_CONTAINER.remove();
}
return ruleContainer.apply(method, describeChild(method), target, statement);
}
use of org.junit.rules.MethodRule in project junit4 by junit-team.
the class RuleContainer method getSortedEntries.
/**
* Returns entries in the order how they should be applied, i.e. inner-to-outer.
*/
private List<RuleEntry> getSortedEntries() {
List<RuleEntry> ruleEntries = new ArrayList<RuleEntry>(methodRules.size() + testRules.size());
for (MethodRule rule : methodRules) {
ruleEntries.add(new RuleEntry(rule, RuleEntry.TYPE_METHOD_RULE, orderValues.get(rule)));
}
for (TestRule rule : testRules) {
ruleEntries.add(new RuleEntry(rule, RuleEntry.TYPE_TEST_RULE, orderValues.get(rule)));
}
Collections.sort(ruleEntries, ENTRY_COMPARATOR);
return ruleEntries;
}
use of org.junit.rules.MethodRule in project spock by spockframework.
the class MethodRuleInterceptor method intercept.
@Override
public void intercept(final IMethodInvocation invocation) throws Throwable {
Statement statement = createBaseStatement(invocation);
FrameworkMethod method = createFrameworkMethod(invocation);
for (FieldInfo field : ruleFields) {
MethodRule rule = (MethodRule) getRuleInstance(field, invocation.getInstance());
statement = rule.apply(statement, method, invocation.getInstance());
}
statement.evaluate();
}
Aggregations