Search in sources :

Example 1 with InvalidSpecException

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));
}
Also used : InvalidSpecException(org.spockframework.runtime.InvalidSpecException) ArrayList(java.util.ArrayList) DynamicProxyMockInterceptorAdapter(org.spockframework.mock.runtime.DynamicProxyMockInterceptorAdapter)

Example 2 with InvalidSpecException

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);
}
Also used : Rollup(spock.lang.Rollup) InvalidSpecException(org.spockframework.runtime.InvalidSpecException) Unroll(spock.lang.Unroll)

Example 3 with InvalidSpecException

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);
        }
    }
}
Also used : SpecInfo(org.spockframework.runtime.model.SpecInfo) InvalidSpecException(org.spockframework.runtime.InvalidSpecException) FeatureInfo(org.spockframework.runtime.model.FeatureInfo)

Example 4 with InvalidSpecException

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;
}
Also used : InvalidSpecException(org.spockframework.runtime.InvalidSpecException)

Example 5 with InvalidSpecException

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);
    }
}
Also used : Rollup(spock.lang.Rollup) InvalidSpecException(org.spockframework.runtime.InvalidSpecException) Unroll(spock.lang.Unroll)

Aggregations

InvalidSpecException (org.spockframework.runtime.InvalidSpecException)6 FeatureInfo (org.spockframework.runtime.model.FeatureInfo)2 Rollup (spock.lang.Rollup)2 Unroll (spock.lang.Unroll)2 Property (io.micronaut.context.annotation.Property)1 MicronautTestValue (io.micronaut.test.annotation.MicronautTestValue)1 MicronautTest (io.micronaut.test.extensions.spock.annotation.MicronautTest)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 DynamicProxyMockInterceptorAdapter (org.spockframework.mock.runtime.DynamicProxyMockInterceptorAdapter)1 FieldInfo (org.spockframework.runtime.model.FieldInfo)1 SpecInfo (org.spockframework.runtime.model.SpecInfo)1