net.jqwik.engine.properties.arbitraries.LazyArbitrary Maven / Gradle / Ivy
package net.jqwik.engine.properties.arbitraries;
import java.util.*;
import java.util.function.*;
import net.jqwik.api.*;
import net.jqwik.api.configurators.*;
import net.jqwik.api.providers.*;
public class LazyArbitrary implements Arbitrary, SelfConfiguringArbitrary {
private final Supplier> arbitrarySupplier;
private List> configurations = new ArrayList<>();
public LazyArbitrary(Supplier> arbitrarySupplier) {this.arbitrarySupplier = arbitrarySupplier;}
@Override
public RandomGenerator generator(int genSize) {
Arbitrary arbitrary = arbitrarySupplier.get();
for (Tuple.Tuple2 configuration : configurations) {
ArbitraryConfigurator configurator = configuration.get1();
TypeUsage targetType = configuration.get2();
if (arbitrary instanceof SelfConfiguringArbitrary) {
// TODO: This condition exists 3 times
//noinspection unchecked
arbitrary = ((SelfConfiguringArbitrary) arbitrary).configure(configurator, targetType);
} else {
arbitrary = configurator.configure(arbitrary, targetType);
}
}
return arbitrary.generator(genSize);
}
@Override
public Arbitrary configure(ArbitraryConfigurator configurator, TypeUsage targetType) {
configurations.add(Tuple.of(configurator, targetType));
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy