All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jqwik.engine.properties.shrinking.IgnoreExceptionShrinkable Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.engine.properties.shrinking;

import java.util.stream.*;

import net.jqwik.api.*;

import org.jspecify.annotations.*;

import static net.jqwik.engine.support.JqwikExceptionSupport.*;

public class IgnoreExceptionShrinkable implements Shrinkable {

	private final Shrinkable shrinkable;
	private final Class[] exceptionTypes;

	public IgnoreExceptionShrinkable(Shrinkable shrinkable, Class[] exceptionTypes) {
		this.shrinkable = shrinkable;
		this.exceptionTypes = exceptionTypes;
	}

	@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 (isInstanceOfAny(throwable, exceptionTypes)) {
					return false;
				}
				throw throwable;
			}
		}).map(shrinkable1 -> new IgnoreExceptionShrinkable(shrinkable1, exceptionTypes));
	}

	@Override
	public ShrinkingDistance distance() {
		return shrinkable.distance();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy