From 92a85fb8c6649f20c0ccfc6c25abb036ac0c9bc3 Mon Sep 17 00:00:00 2001 From: Roman Khlebnov Date: Wed, 2 Oct 2024 21:20:33 +0200 Subject: [PATCH] Improving the API by adding a new way to use throwable functions --- CHANGELOG.md | 19 + README.md | 50 ++- gradle.properties | 2 +- .../github/suppierk/java/{util => }/Try.java | 3 +- .../github/suppierk/java/UnsafeFunctions.java | 217 +++++++++++ .../suppierk/java/lang/ThrowableRunnable.java | 54 +++ .../util/function/ThrowableBiFunction.java | 2 +- .../function/ThrowableBinaryOperator.java | 30 +- .../util/function/ThrowableUnaryOperator.java | 35 +- .../ThrowableFunctionsCallTest.java | 27 +- .../suppierk/java/{util => }/TryTest.java | 2 +- .../suppierk/java/UnsafeFunctionsTest.java | 355 ++++++++++++++++++ 12 files changed, 778 insertions(+), 18 deletions(-) rename src/main/java/io/github/suppierk/java/{util => }/Try.java (99%) create mode 100644 src/main/java/io/github/suppierk/java/UnsafeFunctions.java create mode 100644 src/main/java/io/github/suppierk/java/lang/ThrowableRunnable.java rename src/test/java/io/github/suppierk/java/{util => }/ThrowableFunctionsCallTest.java (95%) rename src/test/java/io/github/suppierk/java/{util => }/TryTest.java (99%) create mode 100644 src/test/java/io/github/suppierk/java/UnsafeFunctionsTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ecee1..08ade88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,31 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.0.0 + +### Added + +- New class `UnsafeFunctions` to allow for easier and more readable access to the functionality +- `ThrowableRunnable` variant of the `Runnable` interface + +### Changed + +- Corrected Javadocs +- **BREAKING**: `ThrowableBinaryOperator` now properly implements `BinaryOperator` interface instead of + `BinaryOperator`'s parent `BiFunction` interface +- **BREAKING**: `ThrowableUnaryOperator` now properly implements `UnaryOperator` interface instead of `UnaryOperator`'s + parent `Function` interface + ## 1.0.3 ### Changed + - Removed restrictions for Try.Success, allowing to save `null` as successful value ## 1.0.2 ### Changed + - Restored Java 8 build compatibility - Adjusted license year - Improved examples in README @@ -21,9 +38,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 1.0.1 ### Added + - Maven Central repository support ## 1.0.0 ### Added + - Initial release with a set of Java functional interfaces and Try \ No newline at end of file diff --git a/README.md b/README.md index 4677124..ba18593 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Java Throwable Utils -This dependency-less library serves for one simple purpose: +This dependency-less library serves for one simple purpose: reduce boilerplate try-catch statements during work with Java Stream API. [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSuppieRK%2Fjava-throwable-utils.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FSuppieRK%2Fjava-throwable-utils?ref=badge_shield) @@ -10,18 +10,20 @@ reduce boilerplate try-catch statements during work with Java Stream API. ## How to add - Maven + ```xml io.github.suppierk java-throwable-utils - 1.0.3 + 2.0.0 ``` - Gradle + ```groovy dependencies { - implementation 'io.github.suppierk:java-throwable-utils:1.0.3' + implementation 'io.github.suppierk:java-throwable-utils:2.0.0' } ``` @@ -133,16 +135,46 @@ public class Demo { } ``` -All exceptions will be propagated using neat trick similar to Apache Commons `ExceptionUtils.rethrow` by leveraging Java type erasure to make checked exceptions unchecked. +or with the help of `UnsafeFunctions` utility class you can shorten it even more without changing your logic too much: + +> This is the recommended, the least intrusive and the least verbose way + +```java +import static io.github.suppierk.java.UnsafeFunctions.*; + +import java.util.ArrayList; +import java.util.List; + +public class Demo { + public static String throwingMethod(String source) throws Exception { + throw new Exception(source); + } + + public static void main(String[] args) { + List test = new ArrayList<>(); + test.add("sample"); + + try { + test.stream() + .map(unsafeFunction(Demo::throwingMethod)) + .forEach(unsafeConsumer(Demo::throwingMethod)); + } catch (Exception e) { + e.printStackTrace(); + } + } +} +``` + +All exceptions will be propagated using neat trick similar to Apache Commons `ExceptionUtils.rethrow` by leveraging Java +type erasure to make checked exceptions unchecked. ## Try -This library has simple implementation of `Try`, -which benefits greatly from presence of these functions +This library has simple implementation of `Try`, which benefits greatly from presence of these functions and allows us to handle exceptions in functional style much like you deal with nullable values using `Optional`. ```java -import io.github.suppierk.java.util.Try; +import io.github.suppierk.java.Try; import java.util.ArrayList; import java.util.List; @@ -164,7 +196,9 @@ public class Test { } ``` -Same as for `Optional`, `Try` in a case of failure will preserve only first exception happened in a call chain and skip further operations. +Same as for `Optional`, `Try` in a case of failure will preserve only first exception happened in a call chain and skip +further operations. ## License + [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSuppieRK%2Fjava-throwable-utils.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FSuppieRK%2Fjava-throwable-utils?ref=badge_large) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index abf5179..4870acf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ SONATYPE_AUTOMATIC_RELEASE=true GROUP=io.github.suppierk POM_ARTIFACT_ID=java-throwable-utils -VERSION_NAME=1.0.3 +VERSION_NAME=2.0.0 POM_NAME=Java Throwable Utilities POM_DESCRIPTION=Java 8 compatible extensions allowing to use checked exceptions in functional programming APIs + Try interface diff --git a/src/main/java/io/github/suppierk/java/util/Try.java b/src/main/java/io/github/suppierk/java/Try.java similarity index 99% rename from src/main/java/io/github/suppierk/java/util/Try.java rename to src/main/java/io/github/suppierk/java/Try.java index d0b7be8..8e2e04d 100644 --- a/src/main/java/io/github/suppierk/java/util/Try.java +++ b/src/main/java/io/github/suppierk/java/Try.java @@ -22,8 +22,9 @@ * SOFTWARE. */ -package io.github.suppierk.java.util; +package io.github.suppierk.java; +import io.github.suppierk.java.util.ExceptionSuppressor; import io.github.suppierk.java.util.function.ThrowableConsumer; import io.github.suppierk.java.util.function.ThrowableFunction; import io.github.suppierk.java.util.function.ThrowablePredicate; diff --git a/src/main/java/io/github/suppierk/java/UnsafeFunctions.java b/src/main/java/io/github/suppierk/java/UnsafeFunctions.java new file mode 100644 index 0000000..63461e2 --- /dev/null +++ b/src/main/java/io/github/suppierk/java/UnsafeFunctions.java @@ -0,0 +1,217 @@ +package io.github.suppierk.java; + +import io.github.suppierk.java.lang.ThrowableRunnable; +import io.github.suppierk.java.util.ThrowableComparator; +import io.github.suppierk.java.util.function.*; +import java.util.Comparator; +import java.util.function.*; + +/** A utility for nicer wrapping of the unsafe function calls. */ +public final class UnsafeFunctions { + private UnsafeFunctions() { + // Utility class + } + + public static Runnable unsafeRunnable(ThrowableRunnable runnable) { + return runnable; + } + + public static BiConsumer unsafeBiConsumer(ThrowableBiConsumer biConsumer) { + return biConsumer; + } + + public static BiFunction unsafeBiFunction( + ThrowableBiFunction biFunction) { + return biFunction; + } + + public static BinaryOperator unsafeBinaryOperator( + ThrowableBinaryOperator binaryOperator) { + return binaryOperator; + } + + public static BiPredicate unsafeBiPredicate(ThrowableBiPredicate biPredicate) { + return biPredicate; + } + + public static BooleanSupplier unsafeBooleanSupplier(ThrowableBooleanSupplier booleanSupplier) { + return booleanSupplier; + } + + public static Consumer unsafeConsumer(ThrowableConsumer consumer) { + return consumer; + } + + public static Comparator unsafeComparator(ThrowableComparator comparator) { + return comparator; + } + + public static DoubleBinaryOperator unsafeDoubleBinaryOperator( + ThrowableDoubleBinaryOperator doubleBinaryOperator) { + return doubleBinaryOperator; + } + + public static DoubleConsumer unsafeDoubleConsumer(ThrowableDoubleConsumer doubleConsumer) { + return doubleConsumer; + } + + public static DoubleFunction unsafeDoubleFunction( + ThrowableDoubleFunction doubleFunction) { + return doubleFunction; + } + + public static DoublePredicate unsafeDoublePredicate(ThrowableDoublePredicate doublePredicate) { + return doublePredicate; + } + + public static DoubleSupplier unsafeDoubleSupplier(ThrowableDoubleSupplier doubleSupplier) { + return doubleSupplier; + } + + public static DoubleToIntFunction unsafeDoubleToIntFunction( + ThrowableDoubleToIntFunction doubleToIntFunction) { + return doubleToIntFunction; + } + + public static DoubleToLongFunction unsafeDoubleToLongFunction( + ThrowableDoubleToLongFunction doubleToLongFunction) { + return doubleToLongFunction; + } + + public static DoubleUnaryOperator unsafeDoubleUnaryOperator( + ThrowableDoubleUnaryOperator doubleUnaryOperator) { + return doubleUnaryOperator; + } + + public static Function unsafeFunction(ThrowableFunction function) { + return function; + } + + public static IntBinaryOperator unsafeIntBinaryOperator( + ThrowableIntBinaryOperator intBinaryOperator) { + return intBinaryOperator; + } + + public static IntConsumer unsafeIntConsumer(ThrowableIntConsumer intConsumer) { + return intConsumer; + } + + public static IntFunction unsafeIntFunction(ThrowableIntFunction intFunction) { + return intFunction; + } + + public static IntPredicate unsafeIntPredicate(ThrowableIntPredicate intPredicate) { + return intPredicate; + } + + public static IntSupplier unsafeIntSupplier(ThrowableIntSupplier intSupplier) { + return intSupplier; + } + + public static IntToDoubleFunction unsafeIntToDoubleFunction( + ThrowableIntToDoubleFunction intToDoubleFunction) { + return intToDoubleFunction; + } + + public static IntToLongFunction unsafeIntToLongFunction( + ThrowableIntToLongFunction intToLongFunction) { + return intToLongFunction; + } + + public static IntUnaryOperator unsafeIntUnaryOperator( + ThrowableIntUnaryOperator intUnaryOperator) { + return intUnaryOperator; + } + + public static LongBinaryOperator unsafeLongBinaryOperator( + ThrowableLongBinaryOperator longBinaryOperator) { + return longBinaryOperator; + } + + public static LongConsumer unsafeLongConsumer(ThrowableLongConsumer longConsumer) { + return longConsumer; + } + + public static LongFunction unsafeLongFunction(ThrowableLongFunction longFunction) { + return longFunction; + } + + public static LongPredicate unsafeLongPredicate(ThrowableLongPredicate longPredicate) { + return longPredicate; + } + + public static LongSupplier unsafeLongSupplier(ThrowableLongSupplier longSupplier) { + return longSupplier; + } + + public static LongToDoubleFunction unsafeLongToDoubleFunction( + ThrowableLongToDoubleFunction longToDoubleFunction) { + return longToDoubleFunction; + } + + public static LongToIntFunction unsafeLongToIntFunction( + ThrowableLongToIntFunction longToIntFunction) { + return longToIntFunction; + } + + public static LongUnaryOperator unsafeLongUnaryOperator( + ThrowableLongUnaryOperator longUnaryOperator) { + return longUnaryOperator; + } + + public static ObjDoubleConsumer unsafeObjDoubleConsumer( + ThrowableObjDoubleConsumer objDoubleConsumer) { + return objDoubleConsumer; + } + + public static ObjIntConsumer unsafeObjIntConsumer( + ThrowableObjIntConsumer objIntConsumer) { + return objIntConsumer; + } + + public static ObjLongConsumer unsafeObjLongConsumer( + ThrowableObjLongConsumer objLongConsumer) { + return objLongConsumer; + } + + public static Predicate unsafePredicate(ThrowablePredicate predicate) { + return predicate; + } + + public static Supplier unsafeSupplier(ThrowableSupplier supplier) { + return supplier; + } + + public static ToDoubleBiFunction unsafeToDoubleBiFunction( + ThrowableToDoubleBiFunction toDoubleBiFunction) { + return toDoubleBiFunction; + } + + public static ToDoubleFunction unsafeToDoubleFunction( + ThrowableToDoubleFunction toDoubleFunction) { + return toDoubleFunction; + } + + public static ToIntBiFunction unsafeToIntBiFunction( + ThrowableToIntBiFunction toIntBiFunction) { + return toIntBiFunction; + } + + public static ToIntFunction unsafeToIntFunction(ThrowableToIntFunction toIntFunction) { + return toIntFunction; + } + + public static ToLongBiFunction unsafeToLongBiFunction( + ThrowableToLongBiFunction toLongBiFunction) { + return toLongBiFunction; + } + + public static ToLongFunction unsafeToLongFunction( + ThrowableToLongFunction toLongFunction) { + return toLongFunction; + } + + public static UnaryOperator unsafeUnaryOperator(ThrowableUnaryOperator unaryOperator) { + return unaryOperator; + } +} diff --git a/src/main/java/io/github/suppierk/java/lang/ThrowableRunnable.java b/src/main/java/io/github/suppierk/java/lang/ThrowableRunnable.java new file mode 100644 index 0000000..32eb219 --- /dev/null +++ b/src/main/java/io/github/suppierk/java/lang/ThrowableRunnable.java @@ -0,0 +1,54 @@ +package io.github.suppierk.java.lang; + +import io.github.suppierk.java.util.ExceptionSuppressor; + +/** + * The {@code Runnable} interface should be implemented by any class whose instances are intended to + * be executed by a thread. The class must define a method of no arguments called {@code run}. + * + *

This interface is designed to provide a common protocol for objects that wish to execute code + * while they are active. For example, {@code Runnable} is implemented by class {@code Thread}. + * Being active simply means that a thread has been started and has not yet been stopped. + * + *

In addition, {@code Runnable} provides the means for a class to be active while not + * subclassing {@code Thread}. A class that implements {@code Runnable} can run without subclassing + * {@code Thread} by instantiating a {@code Thread} instance and passing itself in as the target. In + * most cases, the {@code Runnable} interface should be used if you are only planning to override + * the {@code run()} method and no other {@code Thread} methods. This is important because classes + * should not be subclassed unless the programmer intends on modifying or enhancing the fundamental + * behavior of the class. + * + *

Permits checked exceptions unlike {@link Runnable} + */ +@FunctionalInterface +@SuppressWarnings("squid:S112") +public interface ThrowableRunnable extends Runnable { + /** + * When an object implementing interface {@code ThrowableRunnable} is used to create a thread, + * starting the thread causes the object's {@code run} method to be called in that separately + * executing thread. + * + *

The general contract of the method {@code run} is that it may take any action whatsoever. + * + * @see java.lang.Thread#run() + * @throws Throwable occurred during processing + */ + void runUnsafe() throws Throwable; + + /** + * When an object implementing interface {@code Runnable} is used to create a thread, starting the + * thread causes the object's {@code run} method to be called in that separately executing thread. + * + *

The general contract of the method {@code run} is that it may take any action whatsoever. + * + * @see java.lang.Thread#run() + */ + @Override + default void run() { + try { + runUnsafe(); + } catch (Throwable throwable) { + ExceptionSuppressor.asUnchecked(throwable); + } + } +} diff --git a/src/main/java/io/github/suppierk/java/util/function/ThrowableBiFunction.java b/src/main/java/io/github/suppierk/java/util/function/ThrowableBiFunction.java index 2a1a0e1..dd64638 100644 --- a/src/main/java/io/github/suppierk/java/util/function/ThrowableBiFunction.java +++ b/src/main/java/io/github/suppierk/java/util/function/ThrowableBiFunction.java @@ -32,7 +32,7 @@ * Represents a function that accepts two arguments and produces a result. This is the two-arity * specialization of {@link Function}. * - *

Permits checked exceptions unlike {@link ThrowableBiFunction} + *

Permits checked exceptions unlike {@link BiFunction} * *

This is a functional interface whose functional method is * {@link #apply(Object, Object)}. diff --git a/src/main/java/io/github/suppierk/java/util/function/ThrowableBinaryOperator.java b/src/main/java/io/github/suppierk/java/util/function/ThrowableBinaryOperator.java index 368d805..b1ad242 100644 --- a/src/main/java/io/github/suppierk/java/util/function/ThrowableBinaryOperator.java +++ b/src/main/java/io/github/suppierk/java/util/function/ThrowableBinaryOperator.java @@ -24,9 +24,11 @@ package io.github.suppierk.java.util.function; +import io.github.suppierk.java.util.ExceptionSuppressor; import java.util.Comparator; import java.util.Objects; import java.util.function.BiFunction; +import java.util.function.BinaryOperator; import java.util.function.UnaryOperator; /** @@ -34,7 +36,7 @@ * as the operands. This is a specialization of {@link BiFunction} for the case where the operands * and the result are all of the same type. * - *

Permits checked exceptions unlike {@link java.util.function.BinaryOperator} + *

Permits checked exceptions unlike {@link BinaryOperator} * *

This is a functional interface whose functional method is * {@link #apply(Object, Object)}. @@ -45,7 +47,31 @@ */ @FunctionalInterface @SuppressWarnings("squid:S112") -public interface ThrowableBinaryOperator extends ThrowableBiFunction { +public interface ThrowableBinaryOperator extends BinaryOperator { + /** + * Applies this function to the given argument. + * + * @param t the function argument + * @return the function result + * @throws Throwable occurred during processing + */ + T applyUnsafe(T t, T t2) throws Throwable; + + /** + * Applies this function to the given arguments. + * + * @param t the function argument + * @return the function result + */ + @Override + default T apply(T t, T t2) { + try { + return applyUnsafe(t, t2); + } catch (Throwable throwable) { + return ExceptionSuppressor.asUnchecked(throwable); + } + } + /** * Returns a {@link ThrowableBinaryOperator} which returns the lesser of two elements according to * the specified {@code Comparator}. diff --git a/src/main/java/io/github/suppierk/java/util/function/ThrowableUnaryOperator.java b/src/main/java/io/github/suppierk/java/util/function/ThrowableUnaryOperator.java index e77c962..3d98e31 100644 --- a/src/main/java/io/github/suppierk/java/util/function/ThrowableUnaryOperator.java +++ b/src/main/java/io/github/suppierk/java/util/function/ThrowableUnaryOperator.java @@ -24,12 +24,16 @@ package io.github.suppierk.java.util.function; +import io.github.suppierk.java.util.ExceptionSuppressor; +import java.util.function.Function; +import java.util.function.UnaryOperator; + /** * Represents an operation on a single operand that produces a result of the same type as its * operand. This is a specialization of {@code Function} for the case where the operand and result * are of the same type. * - *

Permits checked exceptions unlike {@link java.util.function.UnaryOperator} + *

Permits checked exceptions unlike {@link UnaryOperator} * *

This is a functional interface whose functional method is * {@link #apply(Object)}. @@ -38,7 +42,34 @@ * @see ThrowableFunction */ @FunctionalInterface -public interface ThrowableUnaryOperator extends ThrowableFunction { +@SuppressWarnings("squid:S112") +public interface ThrowableUnaryOperator extends UnaryOperator { + /** + * Applies this function to the given argument. + * + * @param t the function argument + * @return the function result + * @throws Throwable occurred during processing + */ + T applyUnsafe(T t) throws Throwable; + + /** + * Applies this function to the given argument. + * + *

Has default implementation in order to make {@link #compose(Function)} and {@link + * #andThen(Function)} work. + * + * @param t the function argument + * @return the function result + */ + @Override + default T apply(T t) { + try { + return applyUnsafe(t); + } catch (Throwable throwable) { + return ExceptionSuppressor.asUnchecked(throwable); + } + } /** * Returns a unary operator that always returns its input argument. diff --git a/src/test/java/io/github/suppierk/java/util/ThrowableFunctionsCallTest.java b/src/test/java/io/github/suppierk/java/ThrowableFunctionsCallTest.java similarity index 95% rename from src/test/java/io/github/suppierk/java/util/ThrowableFunctionsCallTest.java rename to src/test/java/io/github/suppierk/java/ThrowableFunctionsCallTest.java index a006a13..4a0810d 100644 --- a/src/test/java/io/github/suppierk/java/util/ThrowableFunctionsCallTest.java +++ b/src/test/java/io/github/suppierk/java/ThrowableFunctionsCallTest.java @@ -22,12 +22,14 @@ * SOFTWARE. */ -package io.github.suppierk.java.util; +package io.github.suppierk.java; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import io.github.suppierk.java.lang.ThrowableRunnable; +import io.github.suppierk.java.util.ThrowableComparator; import io.github.suppierk.java.util.function.ThrowableBiConsumer; import io.github.suppierk.java.util.function.ThrowableBiFunction; import io.github.suppierk.java.util.function.ThrowableBiPredicate; @@ -117,6 +119,13 @@ static Arguments arg(Executable executable) { static Stream executables() { return Stream.of( + arg( + () -> + ((ThrowableRunnable) + () -> { + throw EXCEPTION; + }) + .run()), arg( () -> ((ThrowableBiConsumer) @@ -131,6 +140,13 @@ static Stream executables() { throw EXCEPTION; }) .apply(null, null)), + arg( + () -> + ((ThrowableBinaryOperator) + (s, s2) -> { + throw EXCEPTION; + }) + .apply(null, null)), arg( () -> ThrowableBinaryOperator.minBy( @@ -421,6 +437,13 @@ static Stream executables() { (o1, o2) -> { throw EXCEPTION; }) - .compare(null, null))); + .compare(null, null)), + arg( + () -> + ((ThrowableUnaryOperator) + s -> { + throw EXCEPTION; + }) + .apply(null))); } } diff --git a/src/test/java/io/github/suppierk/java/util/TryTest.java b/src/test/java/io/github/suppierk/java/TryTest.java similarity index 99% rename from src/test/java/io/github/suppierk/java/util/TryTest.java rename to src/test/java/io/github/suppierk/java/TryTest.java index f3f048b..e8cc7b7 100644 --- a/src/test/java/io/github/suppierk/java/util/TryTest.java +++ b/src/test/java/io/github/suppierk/java/TryTest.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package io.github.suppierk.java.util; +package io.github.suppierk.java; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/io/github/suppierk/java/UnsafeFunctionsTest.java b/src/test/java/io/github/suppierk/java/UnsafeFunctionsTest.java new file mode 100644 index 0000000..51afc5b --- /dev/null +++ b/src/test/java/io/github/suppierk/java/UnsafeFunctionsTest.java @@ -0,0 +1,355 @@ +package io.github.suppierk.java; + +import static io.github.suppierk.java.UnsafeFunctions.*; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import io.github.suppierk.java.util.function.*; +import java.util.stream.Stream; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class UnsafeFunctionsTest { + private static final Exception EXCEPTION = new Exception(); + + @ParameterizedTest + @MethodSource("executables") + void assertThatFunctionCanBeCalled(Executable expectedToFail) { + assertThrows(Exception.class, expectedToFail, "Failed to do call returning exception"); + } + + static Arguments arg(Executable executable) { + return Arguments.of(executable); + } + + static Stream executables() { + return Stream.of( + arg( + () -> + unsafeRunnable( + () -> { + throw EXCEPTION; + }) + .run()), + arg( + () -> + unsafeBiConsumer( + (s, s2) -> { + throw EXCEPTION; + }) + .accept(null, null)), + arg( + () -> + unsafeBiFunction( + (s, s2) -> { + throw EXCEPTION; + }) + .apply(null, null)), + arg( + () -> + unsafeBinaryOperator( + (s, s2) -> { + throw EXCEPTION; + }) + .apply(null, null)), + arg( + () -> + ThrowableBinaryOperator.minBy( + unsafeComparator( + (o1, o2) -> { + throw EXCEPTION; + })) + .apply(null, null)), + arg( + () -> + ThrowableBinaryOperator.maxBy( + unsafeComparator( + (o1, o2) -> { + throw EXCEPTION; + })) + .apply(null, null)), + arg( + () -> + unsafeBiPredicate( + (s, s2) -> { + throw EXCEPTION; + }) + .test(null, null)), + arg( + unsafeBooleanSupplier( + () -> { + throw EXCEPTION; + }) + ::getAsBoolean), + arg( + () -> + unsafeConsumer( + s -> { + throw EXCEPTION; + }) + .accept(null)), + arg( + () -> + unsafeDoubleBinaryOperator( + (left, right) -> { + throw EXCEPTION; + }) + .applyAsDouble(.0, .0)), + arg( + () -> + unsafeDoubleConsumer( + value -> { + throw EXCEPTION; + }) + .accept(.0)), + arg( + () -> + unsafeDoubleFunction( + value -> { + throw EXCEPTION; + }) + .apply(.0)), + arg( + () -> + unsafeDoublePredicate( + value -> { + throw EXCEPTION; + }) + .test(.0)), + arg( + unsafeDoubleSupplier( + () -> { + throw EXCEPTION; + }) + ::getAsDouble), + arg( + () -> + unsafeDoubleToIntFunction( + value -> { + throw EXCEPTION; + }) + .applyAsInt(.0)), + arg( + () -> + unsafeDoubleToLongFunction( + value -> { + throw EXCEPTION; + }) + .applyAsLong(.0)), + arg( + () -> + unsafeDoubleUnaryOperator( + operand -> { + throw EXCEPTION; + }) + .applyAsDouble(.0)), + arg( + () -> + unsafeFunction( + s -> { + throw EXCEPTION; + }) + .apply(null)), + arg( + () -> + unsafeIntBinaryOperator( + (left, right) -> { + throw EXCEPTION; + }) + .applyAsInt(0, 0)), + arg( + () -> + unsafeIntConsumer( + value -> { + throw EXCEPTION; + }) + .accept(0)), + arg( + () -> + unsafeIntFunction( + value -> { + throw EXCEPTION; + }) + .apply(0)), + arg( + () -> + unsafeIntPredicate( + value -> { + throw EXCEPTION; + }) + .test(0)), + arg( + unsafeIntSupplier( + () -> { + throw EXCEPTION; + }) + ::getAsInt), + arg( + () -> + unsafeIntToDoubleFunction( + value -> { + throw EXCEPTION; + }) + .applyAsDouble(0)), + arg( + () -> + unsafeIntToLongFunction( + value -> { + throw EXCEPTION; + }) + .applyAsLong(0)), + arg( + () -> + unsafeIntUnaryOperator( + operand -> { + throw EXCEPTION; + }) + .applyAsInt(0)), + arg( + () -> + unsafeLongBinaryOperator( + (left, right) -> { + throw EXCEPTION; + }) + .applyAsLong(0L, 0L)), + arg( + () -> + unsafeLongConsumer( + value -> { + throw EXCEPTION; + }) + .accept(0L)), + arg( + () -> + unsafeLongFunction( + value -> { + throw EXCEPTION; + }) + .apply(0L)), + arg( + () -> + unsafeLongPredicate( + value -> { + throw EXCEPTION; + }) + .test(0L)), + arg( + unsafeLongSupplier( + () -> { + throw EXCEPTION; + }) + ::getAsLong), + arg( + () -> + unsafeLongToDoubleFunction( + value -> { + throw EXCEPTION; + }) + .applyAsDouble(0L)), + arg( + () -> + unsafeLongToIntFunction( + value -> { + throw EXCEPTION; + }) + .applyAsInt(0L)), + arg( + () -> + unsafeLongUnaryOperator( + operand -> { + throw EXCEPTION; + }) + .applyAsLong(0L)), + arg( + () -> + unsafeObjDoubleConsumer( + (s, value) -> { + throw EXCEPTION; + }) + .accept(null, .0)), + arg( + () -> + unsafeObjIntConsumer( + (s, value) -> { + throw EXCEPTION; + }) + .accept(null, 0)), + arg( + () -> + unsafeObjLongConsumer( + (s, value) -> { + throw EXCEPTION; + }) + .accept(null, 0L)), + arg( + () -> + unsafePredicate( + s -> { + throw EXCEPTION; + }) + .test(null)), + arg( + unsafeSupplier( + () -> { + throw EXCEPTION; + }) + ::get), + arg( + () -> + unsafeToDoubleBiFunction( + (s, s2) -> { + throw EXCEPTION; + }) + .applyAsDouble(null, null)), + arg( + () -> + unsafeToDoubleFunction( + value -> { + throw EXCEPTION; + }) + .applyAsDouble(null)), + arg( + () -> + unsafeToIntBiFunction( + (s, s2) -> { + throw EXCEPTION; + }) + .applyAsInt(null, null)), + arg( + () -> + unsafeToIntFunction( + value -> { + throw EXCEPTION; + }) + .applyAsInt(null)), + arg( + () -> + unsafeToLongBiFunction( + (s, s2) -> { + throw EXCEPTION; + }) + .applyAsLong(null, null)), + arg( + () -> + unsafeToLongFunction( + value -> { + throw EXCEPTION; + }) + .applyAsLong(null)), + arg( + () -> + unsafeComparator( + (o1, o2) -> { + throw EXCEPTION; + }) + .compare(null, null)), + arg( + () -> + unsafeUnaryOperator( + s -> { + throw EXCEPTION; + }) + .apply(null))); + } +}