net.jqwik.engine.properties.arbitraries.IgnoreGenerationErrorArbitrary Maven / Gradle / Ivy
package net.jqwik.engine.properties.arbitraries;
import java.util.*;
import net.jqwik.api.*;
//Currently only used in DefaultTypeArbitrary
//Support configurators if this class is used somewhere else
class IgnoreGenerationErrorArbitrary implements Arbitrary {
private Arbitrary arbitrary;
IgnoreGenerationErrorArbitrary(Arbitrary arbitrary) {
this.arbitrary = arbitrary;
}
@Override
public RandomGenerator generator(int genSize) {
RandomGenerator generator = arbitrary.generator(genSize);
return random -> {
int count = 0;
while (count++ < 1000) {
try {
Shrinkable next = generator.next(random);
return next;
} catch (GenerationError ignore) {
}
}
String message = String.format("Too many exceptions while generating values with %s", arbitrary.toString());
throw new JqwikException(message);
};
}
@Override
public Optional> exhaustive() {
// Support exhaustive generation if this class is used somewhere else
return Optional.empty();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy