nl.hsac.fitnesse.fixture.util.ThrowingFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hsac-fitnesse-fixtures Show documentation
Show all versions of hsac-fitnesse-fixtures Show documentation
Fixtures to assist in testing via FitNesse
package nl.hsac.fitnesse.fixture.util;
import java.util.function.Function;
/**
* Functional interface to allow exceptions thrown by lambdas to be handled, or wrapped to runtime ones.
*/
@FunctionalInterface
public interface ThrowingFunction {
R apply(T t) throws E;
/**
* Applies using t, wrapping converting any checked exception to a runtime one using exceptionWrapper
* @param t parameter to supply to {@link #apply(Object)}.
* @param exceptionWrapper function to convert checked exception to runtime one.
* @param type of runtime exception which will be thrown
* @return result of apply(t)
*/
default R applyWrapped(T t, Function exceptionWrapper) {
try {
return apply(t);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw exceptionWrapper.apply((E) e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy