use of org.spockframework.runtime.model.FeatureInfo in project ratpack by ratpack.
the class TempDirExtension method visitFieldAnnotation.
@Override
public void visitFieldAnnotation(TempDir annotation, FieldInfo field) {
Class<?> fieldType = field.getType();
if (!fieldType.isAssignableFrom(TemporaryFolder.class)) {
throw new InvalidSpecException("@TempDir can only be used on TemporaryFolder");
}
TempDirInterceptor interceptor = new TempDirInterceptor(fieldType, field, configuration.baseDir, configuration.keep);
// attach interceptor
SpecInfo specInfo = field.getParent();
if (field.isShared()) {
specInfo.addInterceptor(interceptor);
} else {
for (FeatureInfo featureInfo : specInfo.getBottomSpec().getAllFeatures()) {
featureInfo.addIterationInterceptor(interceptor);
}
}
}
use of org.spockframework.runtime.model.FeatureInfo in project gradle by gradle.
the class MultiTestExtension method visitSpecAnnotation.
@Override
public void visitSpecAnnotation(T annotation, SpecInfo spec) {
if (!spec.getFeatures().isEmpty()) {
AbstractMultiTestInterceptor interceptor = makeInterceptor(spec.getBottomSpec().getReflection());
spec.addInitializerInterceptor(interceptor);
for (FeatureInfo feature : spec.getFeatures()) {
interceptor.interceptFeature(feature);
}
}
}
use of org.spockframework.runtime.model.FeatureInfo in project micronaut-test by micronaut-projects.
the class MicronautSpockExtension method visitSpecAnnotation.
@Override
public void visitSpecAnnotation(T annotation, SpecInfo spec) {
spec.getAllFeatures().forEach(feature -> {
feature.addInterceptor(invocation -> {
try {
beforeTestMethod(buildContext(invocation, null));
invocation.proceed();
} finally {
afterTestMethod(buildContext(invocation, null));
}
});
feature.getFeatureMethod().addInterceptor(invocation -> {
try {
beforeTestExecution(buildContext(invocation, null));
invocation.proceed();
afterTestExecution(buildContext(invocation, null));
} catch (Throwable e) {
afterTestExecution(buildContext(invocation, e));
throw e;
}
});
});
spec.addSetupSpecInterceptor(invocation -> {
MicronautTest micronautTest = spec.getAnnotation(MicronautTest.class);
MicronautTestValue micronautTestValue = buildValueObject(micronautTest);
beforeClass(invocation, spec.getReflection(), micronautTestValue);
if (specDefinition == null) {
if (!isTestSuiteBeanPresent(spec.getReflection())) {
throw new InvalidSpecException(MISCONFIGURED_MESSAGE);
} else {
final List<FeatureInfo> features = invocation.getSpec().getFeatures();
for (FeatureInfo feature : features) {
feature.setSkipped(true);
}
}
} else {
List<FieldInfo> fields = spec.getAllFields();
for (FieldInfo field : fields) {
if (field.isShared() && field.getAnnotation(Inject.class) != null) {
applicationContext.inject(invocation.getSharedInstance());
break;
}
}
}
beforeTestClass(buildContext(invocation, null));
invocation.proceed();
});
spec.addCleanupSpecInterceptor(invocation -> {
afterTestClass(buildContext(invocation, null));
afterClass(invocation);
invocation.proceed();
singletonMocks.clear();
});
spec.addSetupInterceptor(invocation -> {
final Object instance = invocation.getInstance();
final Method method = invocation.getFeature().getFeatureMethod().getReflection();
List<Property> propertyAnnotations = Arrays.asList(method.getAnnotationsByType(Property.class));
beforeEach(invocation, instance, method, propertyAnnotations);
for (Object mock : creatableMocks) {
mockUtil.attachMock(mock, (Specification) instance);
}
for (Object mock : singletonMocks) {
mockUtil.attachMock(mock, (Specification) instance);
}
try {
beforeSetupTest(buildContext(invocation, null));
invocation.proceed();
} finally {
afterSetupTest(buildContext(invocation, null));
}
});
spec.addCleanupInterceptor(invocation -> {
for (Object mock : creatableMocks) {
mockUtil.detachMock(mock);
}
for (Object mock : singletonMocks) {
mockUtil.detachMock(mock);
}
creatableMocks.clear();
afterEach(invocation);
try {
beforeCleanupTest(buildContext(invocation, null));
invocation.proceed();
} finally {
afterCleanupTest(buildContext(invocation, null));
}
});
}
Aggregations