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.*;

public class IgnoreExceptionShrinkable implements Shrinkable {

	private final Shrinkable shrinkable;
	private final Class exceptionType;

	public IgnoreExceptionShrinkable(Shrinkable shrinkable, Class 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