use of org.spockframework.runtime.InvalidSpecException in project spock by spockframework.
the class DynamicProxyMockFactory method createMock.
static Object createMock(Class<?> mockType, List<Class<?>> additionalInterfaces, List<Object> constructorArgs, IProxyBasedMockInterceptor mockInterceptor, ClassLoader classLoader) {
if (constructorArgs != null) {
throw new InvalidSpecException("Interface based mocks may not have constructor arguments");
}
List<Class<?>> interfaces = new ArrayList<>();
interfaces.add(mockType);
interfaces.addAll(additionalInterfaces);
interfaces.add(ISpockMockObject.class);
return Proxy.newProxyInstance(classLoader, interfaces.toArray(CLASSES), new DynamicProxyMockInterceptorAdapter(mockInterceptor));
}
use of org.spockframework.runtime.InvalidSpecException in project spock by spockframework.
the class UnrollExtension method visitFeature.
private void visitFeature(FeatureInfo feature, boolean doUnrollSpec, String specUnrollPattern) {
MethodInfo featureMethod = feature.getFeatureMethod();
Unroll unroll = featureMethod.getAnnotation(Unroll.class);
boolean unrollFeature = unroll != null;
boolean rollupFeature = featureMethod.getAnnotation(Rollup.class) != null;
if (unrollFeature && rollupFeature) {
throw new InvalidSpecException("@Unroll and @Rollup must not be used on the same feature: " + feature.getName());
}
boolean doUnrollFeature;
String featureUnrollPattern;
if (unrollFeature) {
doUnrollFeature = true;
featureUnrollPattern = unroll.value();
} else if (rollupFeature) {
doUnrollFeature = false;
featureUnrollPattern = "";
} else {
doUnrollFeature = doUnrollSpec;
featureUnrollPattern = "";
}
feature.setReportIterations(doUnrollFeature);
feature.setIterationNameProvider(doUnrollFeature ? chooseNameProvider(specUnrollPattern, featureUnrollPattern, feature) : null);
}
use of org.spockframework.runtime.InvalidSpecException 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.InvalidSpecException in project spock by spockframework.
the class InteractionBuilder method setRangeCount.
public InteractionBuilder setRangeCount(Object minCount, Object maxCount, boolean inclusive) {
this.minCount = minCount instanceof Wildcard ? 0 : convertCount(minCount, true);
this.maxCount = maxCount instanceof Wildcard ? Integer.MAX_VALUE : convertCount(maxCount, inclusive);
if (this.minCount > this.maxCount)
throw new InvalidSpecException("lower bound of invocation count must come before upper bound");
return this;
}
use of org.spockframework.runtime.InvalidSpecException in project spock by spockframework.
the class UnrollExtension method visitSpec.
@Override
public void visitSpec(SpecInfo spec) {
Unroll unroll = spec.getAnnotation(Unroll.class);
boolean unrollSpec = unroll != null;
boolean rollupSpec = spec.getAnnotation(Rollup.class) != null;
if (unrollSpec && rollupSpec) {
throw new InvalidSpecException("@Unroll and @Rollup must not be used on the same spec: " + spec.getName());
}
boolean doUnrollSpec;
String specUnrollPattern;
if (unrollSpec) {
doUnrollSpec = true;
specUnrollPattern = unroll.value();
} else if (rollupSpec) {
doUnrollSpec = false;
specUnrollPattern = "";
} else {
doUnrollSpec = unrollConfiguration.unrollByDefault;
specUnrollPattern = "";
}
spec.getFeatures().stream().filter(FeatureInfo::isParameterized).forEach(feature -> visitFeature(feature, doUnrollSpec, specUnrollPattern));
SpecInfo superSpec = spec.getSuperSpec();
if (superSpec != null) {
visitSpec(superSpec);
}
}
Aggregations