Search in sources :

Example 1 with AutoCleanup

use of spock.lang.AutoCleanup 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);
}
Also used : AutoCleanup(spock.lang.AutoCleanup) FieldInfo(org.spockframework.runtime.model.FieldInfo)

Aggregations

FieldInfo (org.spockframework.runtime.model.FieldInfo)1 AutoCleanup (spock.lang.AutoCleanup)1