net.jqwik.engine.execution.ResolvingParametersGenerator Maven / Gradle / Ivy
package net.jqwik.engine.execution;
import java.util.*;
import net.jqwik.api.*;
import net.jqwik.api.lifecycle.*;
import net.jqwik.api.lifecycle.ResolveParameterHook.*;
import net.jqwik.engine.properties.*;
import net.jqwik.engine.support.*;
public class ResolvingParametersGenerator implements ParametersGenerator {
private final List propertyParameters;
private final ForAllParametersGenerator forAllParametersGenerator;
private final ParameterSupplierResolver parameterSupplierResolver;
private int currentGenerationIndex = 0;
public ResolvingParametersGenerator(
List propertyParameters,
ForAllParametersGenerator forAllParametersGenerator,
ResolveParameterHook resolveParameterHook,
PropertyLifecycleContext propertyLifecycleContext
) {
this.propertyParameters = propertyParameters;
this.forAllParametersGenerator = forAllParametersGenerator;
this.parameterSupplierResolver = new ParameterSupplierResolver(resolveParameterHook, propertyLifecycleContext);
}
@Override
public boolean hasNext() {
return forAllParametersGenerator.hasNext();
}
@Override
public List> next(TryLifecycleContext context) {
List> next = new ArrayList<>();
List> forAllShrinkables = new ArrayList<>(forAllParametersGenerator.next());
for (MethodParameter parameter : propertyParameters) {
if (parameter.isAnnotated(ForAll.class)) {
next.add(forAllShrinkables.get(0));
forAllShrinkables.remove(0);
} else {
next.add(findResolvableParameter(parameter, context));
}
}
currentGenerationIndex++;
return next;
}
@Override
public int edgeCasesTotal() {
return forAllParametersGenerator.edgeCasesTotal();
}
@Override
public int edgeCasesTried() {
return forAllParametersGenerator.edgeCasesTried();
}
@Override
public GenerationInfo generationInfo(String randomSeed) {
return new GenerationInfo(randomSeed, currentGenerationIndex);
}
private Shrinkable