net.jqwik.engine.properties.shrinking.IgnoreExceptionShrinkable Maven / Gradle / Ivy
package net.jqwik.engine.properties.shrinking;
import java.util.stream.*;
import net.jqwik.api.*;
public class IgnoreExceptionShrinkable implements Shrinkable {
private final Shrinkable shrinkable;
private final Class extends Throwable> exceptionType;
public IgnoreExceptionShrinkable(Shrinkable shrinkable, Class extends Throwable> exceptionType) {
this.shrinkable = shrinkable;
this.exceptionType = exceptionType;
}
@Override
public T value() {
return shrinkable.value();
}
@Override
public Stream> shrink() {
return shrinkable.shrink().filter(s -> {
try {
s.value();
return true;
} catch (Throwable throwable) {
if (exceptionType.isAssignableFrom(throwable.getClass())) {
return false;
}
throw throwable;
}
}).map(shrinkable1 -> new IgnoreExceptionShrinkable(shrinkable1, exceptionType));
}
@Override
public ShrinkingDistance distance() {
return shrinkable.distance();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy