use of org.spockframework.runtime.model.FieldInfo in project spock by spockframework.
the class AutoCleanupInterceptor method intercept.
public void intercept(IMethodInvocation invocation) throws Throwable {
List<Throwable> exceptions = new ArrayList<Throwable>();
try {
invocation.proceed();
} catch (Throwable t) {
exceptions.add(t);
}
for (FieldInfo field : fields) {
AutoCleanup annotation = field.getAnnotation(AutoCleanup.class);
try {
Object value = field.readValue(invocation.getInstance());
if (value == null)
continue;
GroovyRuntimeUtil.invokeMethod(value, annotation.value());
} catch (Throwable t) {
if (!annotation.quiet())
exceptions.add(t);
}
}
ExtensionUtil.throwAll(exceptions);
}
use of org.spockframework.runtime.model.FieldInfo in project spock by spockframework.
the class ClassRuleInterceptor method intercept.
public void intercept(final IMethodInvocation invocation) throws Throwable {
Statement stat = createBaseStatement(invocation);
for (FieldInfo field : ruleFields) {
TestRule rule = (TestRule) getRuleInstance(field, field.isShared() ? invocation.getSharedInstance() : invocation.getInstance());
stat = rule.apply(stat, invocation.getSpec().getDescription());
}
stat.evaluate();
}
use of org.spockframework.runtime.model.FieldInfo in project spock by spockframework.
the class MethodRuleInterceptor method intercept.
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();
}
use of org.spockframework.runtime.model.FieldInfo in project spock by spockframework.
the class TestRuleInterceptor method intercept.
public void intercept(final IMethodInvocation invocation) throws Throwable {
Statement stat = createBaseStatement(invocation);
for (FieldInfo field : ruleFields) {
TestRule rule = (TestRule) getRuleInstance(field, invocation.getInstance());
stat = rule.apply(stat, invocation.getIteration().getDescription());
}
stat.evaluate();
}
use of org.spockframework.runtime.model.FieldInfo in project spock by spockframework.
the class RuleExtension method visitSpec.
public void visitSpec(SpecInfo spec) {
if (ruleClass == null)
return;
List<FieldInfo> methodRuleFields = new ArrayList<FieldInfo>();
List<FieldInfo> testRuleFields = new ArrayList<FieldInfo>();
for (FieldInfo field : spec.getAllFields()) {
if (!field.isAnnotationPresent(ruleClass))
continue;
checkIsInstanceField(field);
if (hasFieldType(field, methodRuleClass)) {
methodRuleFields.add(field);
} else if (hasFieldType(field, testRuleClass)) {
testRuleFields.add(field);
} else {
invalidFieldType(field);
}
}
if (!methodRuleFields.isEmpty())
MethodRuleInterceptorInstaller.install(spec, methodRuleFields);
if (!testRuleFields.isEmpty())
TestRuleInterceptorInstaller.install(spec, testRuleFields);
}
Aggregations