net.jqwik.engine.execution.CheckedProperty Maven / Gradle / Ivy
package net.jqwik.engine.execution;
import java.util.*;
import java.util.function.*;
import org.junit.platform.engine.reporting.*;
import net.jqwik.api.*;
import net.jqwik.engine.descriptor.*;
import net.jqwik.engine.properties.*;
import net.jqwik.engine.support.*;
public class CheckedProperty {
public final String propertyName;
public final CheckedFunction checkedFunction;
public final List forAllParameters;
private final ArbitraryResolver arbitraryResolver;
private final Optional> optionalData;
public final PropertyConfiguration configuration;
private final Optional optionalExhaustive;
public CheckedProperty(
String propertyName, CheckedFunction checkedFunction, List forAllParameters,
ArbitraryResolver arbitraryResolver, Optional> optionalData, PropertyConfiguration configuration
) {
this.propertyName = propertyName;
this.checkedFunction = checkedFunction;
this.forAllParameters = forAllParameters;
this.arbitraryResolver = arbitraryResolver;
this.optionalData = optionalData;
this.configuration = configuration;
this.optionalExhaustive = createExhaustiveShrinkablesGenerator();
}
public PropertyCheckResult check(Consumer publisher, Reporting[] reporting, boolean reportOnlyFailures) {
PropertyConfiguration effectiveConfiguration = configurationWithEffectiveSeed();
try {
return createGenericProperty(effectiveConfiguration).check(publisher, reporting, reportOnlyFailures);
} catch (CannotFindArbitraryException cannotFindArbitraryException) {
return PropertyCheckResult.erroneous(
effectiveConfiguration.getStereotype(), propertyName, 0, 0, effectiveConfiguration.getSeed(),
configuration.getGenerationMode(), Collections.emptyList(), null, cannotFindArbitraryException
);
}
}
private PropertyConfiguration configurationWithEffectiveSeed() {
if (!configuration.getSeed().equals(Property.SEED_NOT_SET)) {
return configuration.withSeed(configuration.getSeed());
}
if (configuration.getPreviousSeed() != null && configuration.getAfterFailureMode() != AfterFailureMode.RANDOM_SEED) {
return configuration.withSeed(configuration.getPreviousSeed());
}
return configuration.withSeed(SourceOfRandomness.createRandomSeed());
}
private GenericProperty createGenericProperty(PropertyConfiguration configuration) {
if (configuration.getGenerationMode() == GenerationMode.AUTO) {
configuration = chooseGenerationMode(configuration);
} else if (configuration.getGenerationMode() == GenerationMode.DATA_DRIVEN) {
ensureValidDataDrivenMode();
} else if (configuration.getGenerationMode() == GenerationMode.EXHAUSTIVE) {
ensureValidExhaustiveMode();
configuration = configuration.withTries(Math.toIntExact(optionalExhaustive.get().maxCount()));
} else if (configuration.getGenerationMode() == GenerationMode.RANDOMIZED) {
ensureValidRandomizedMode();
}
ShrinkablesGenerator shrinkablesGenerator = createShrinkablesGenerator(configuration);
return new GenericProperty(propertyName, configuration, shrinkablesGenerator, checkedFunction);
}
private ShrinkablesGenerator createShrinkablesGenerator(PropertyConfiguration configuration) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy