Search in sources :

Example 1 with Unroll

use of spock.lang.Unroll 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 2 with Unroll

use of spock.lang.Unroll 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)2 Rollup (spock.lang.Rollup)2 Unroll (spock.lang.Unroll)2