diff --git a/vavr/generator/Generator.scala b/vavr/generator/Generator.scala index 8644709d01..f99113b1bd 100644 --- a/vavr/generator/Generator.scala +++ b/vavr/generator/Generator.scala @@ -395,7 +395,7 @@ def generateMainClasses(): Unit = { * ${(0 to i).gen(j => if (j == 0) "* @param return type" else s"* @param type of the ${j.ordinal} argument")("\n")} * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction$i} + * @return An unchecked wrapper of supplied {@link CheckedFunction$i} */ public static $fullGenerics Function$i$fullGenerics unchecked(CheckedFunction$i$fullGenerics f) { return f.unchecked(); @@ -1445,6 +1445,8 @@ def generateMainClasses(): Unit = { case _ => s"$i arguments" } + im.getStatic(s"io.vavr.${className}Module.sneakyThrow") + xs""" /** * Represents a function with ${arguments(i)}. @@ -1700,26 +1702,18 @@ def generateMainClasses(): Unit = { } /$javadoc - * Return unchecked function that will return this $className result in correct case and throw runtime exception - * wrapped by {@code exceptionMapper} in case of throwable - * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function$i that wraps this CheckedFunction$i by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function$i$fullGenerics unchecked(${im.getType("java.util.function.Function")} exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /$javadoc - * Return unchecked function that will return this $className result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. + * Returns an unchecked function that will sneaky throw if an exceptions occurs when applying the function. * - * @return a new Function$i that wraps this CheckedFunction$i by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function$i that throws a {@code Throwable}. */ default Function$i$fullGenerics unchecked() { - return unchecked(IllegalStateException::new); + return ($params) -> { + try { + return apply($params); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } """)} @@ -1753,6 +1747,15 @@ def generateMainClasses(): Unit = { } """)} } + + interface ${className}Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } + } """ } }) @@ -3039,11 +3042,11 @@ def generateTestClasses(): Unit = { assertThat(md5.getDigestLength()).isEqualTo(16); } - @$test(expected = IllegalStateException.class) - public void shouldUncheckedThrowIllegalState() { + @$test(expected = ${im.getType("java.security.NoSuchAlgorithmException")}.class) + public void shouldThrowCheckedExceptionWhenUnchecked() { $name$i digest = () -> ${im.getType("java.security.MessageDigest")}.getInstance("Unknown"); Function$i unchecked = digest.unchecked(); - unchecked.apply(); + unchecked.apply(); // Look ma, we throw an undeclared checked exception! } @$test @@ -3074,8 +3077,8 @@ def generateTestClasses(): Unit = { @$test public void shouldRecover() { - Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> recover = digest.recover(throwable -> (${(1 to i).gen(j => s"s$j")(", ")}) -> null); - MessageDigest md5 = recover.apply(${toArgList("MD5")}); + final Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> recover = digest.recover(throwable -> (${(1 to i).gen(j => s"s$j")(", ")}) -> null); + final MessageDigest md5 = recover.apply(${toArgList("MD5")}); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -3084,12 +3087,12 @@ def generateTestClasses(): Unit = { @$test public void shouldRecoverNonNull() { - Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply(${toArgList("MD5")}); + final Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply(${toArgList("MD5")}); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - ${im.getType("io.vavr.control.Try")} unknown = Function$i.liftTry(recover).apply(${toArgList("Unknown")}); + final ${im.getType("io.vavr.control.Try")} unknown = Function$i.liftTry(recover).apply(${toArgList("Unknown")}); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -3098,28 +3101,28 @@ def generateTestClasses(): Unit = { @$test public void shouldUncheckedWork() { - Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply(${toArgList("MD5")}); + final Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply(${toArgList("MD5")}); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @$test(expected = IllegalStateException.class) + @$test(expected = ${im.getType("java.security.NoSuchAlgorithmException")}.class) public void shouldUncheckedThrowIllegalState() { - Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> unchecked = digest.unchecked(); - unchecked.apply(${toArgList("Unknown")}); + final Function$i<${(1 to i).gen(j => "String")(", ")}, MessageDigest> unchecked = digest.unchecked(); + unchecked.apply(${toArgList("Unknown")}); // Look ma, we throw an undeclared checked exception! } @$test public void shouldLiftTryPartialFunction() { - Function$i<${(1 to i).gen(j => "String")(", ")}, Try> liftTry = $name$i.liftTry(digest); - ${im.getType("io.vavr.control.Try")} md5 = liftTry.apply(${toArgList("MD5")}); + final Function$i<${(1 to i).gen(j => "String")(", ")}, Try> liftTry = $name$i.liftTry(digest); + final ${im.getType("io.vavr.control.Try")} md5 = liftTry.apply(${toArgList("MD5")}); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - ${im.getType("io.vavr.control.Try")} unknown = liftTry.apply(${toArgList("Unknown")}); + final ${im.getType("io.vavr.control.Try")} unknown = liftTry.apply(${toArgList("Unknown")}); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/main/java/io/vavr/API.java b/vavr/src-gen/main/java/io/vavr/API.java index 714828e141..5b7e72ab73 100644 --- a/vavr/src-gen/main/java/io/vavr/API.java +++ b/vavr/src-gen/main/java/io/vavr/API.java @@ -461,7 +461,7 @@ public static CheckedFunction8 return type * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction0} + * @return An unchecked wrapper of supplied {@link CheckedFunction0} */ public static Function0 unchecked(CheckedFunction0 f) { return f.unchecked(); @@ -473,7 +473,7 @@ public static Function0 unchecked(CheckedFunction0 f) { * @param return type * @param type of the 1st argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction1} + * @return An unchecked wrapper of supplied {@link CheckedFunction1} */ public static Function1 unchecked(CheckedFunction1 f) { return f.unchecked(); @@ -486,7 +486,7 @@ public static Function1 unchecked(CheckedFunction1 f) { * @param type of the 1st argument * @param type of the 2nd argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction2} + * @return An unchecked wrapper of supplied {@link CheckedFunction2} */ public static Function2 unchecked(CheckedFunction2 f) { return f.unchecked(); @@ -500,7 +500,7 @@ public static Function2 unchecked(CheckedFunction2 type of the 2nd argument * @param type of the 3rd argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction3} + * @return An unchecked wrapper of supplied {@link CheckedFunction3} */ public static Function3 unchecked(CheckedFunction3 f) { return f.unchecked(); @@ -515,7 +515,7 @@ public static Function3 unchecked(CheckedFunction * @param type of the 3rd argument * @param type of the 4th argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction4} + * @return An unchecked wrapper of supplied {@link CheckedFunction4} */ public static Function4 unchecked(CheckedFunction4 f) { return f.unchecked(); @@ -531,7 +531,7 @@ public static Function4 unchecked(Checked * @param type of the 4th argument * @param type of the 5th argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction5} + * @return An unchecked wrapper of supplied {@link CheckedFunction5} */ public static Function5 unchecked(CheckedFunction5 f) { return f.unchecked(); @@ -548,7 +548,7 @@ public static Function5 unchecked * @param type of the 5th argument * @param type of the 6th argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction6} + * @return An unchecked wrapper of supplied {@link CheckedFunction6} */ public static Function6 unchecked(CheckedFunction6 f) { return f.unchecked(); @@ -566,7 +566,7 @@ public static Function6 u * @param type of the 6th argument * @param type of the 7th argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction7} + * @return An unchecked wrapper of supplied {@link CheckedFunction7} */ public static Function7 unchecked(CheckedFunction7 f) { return f.unchecked(); @@ -585,7 +585,7 @@ public static Function7 type of the 7th argument * @param type of the 8th argument * @param f A method reference - * @return A unchecked wrapper of supplied {@link CheckedFunction8} + * @return An unchecked wrapper of supplied {@link CheckedFunction8} */ public static Function8 unchecked(CheckedFunction8 f) { return f.unchecked(); diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction0.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction0.java index 401a722493..b2e9ba3397 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction0.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction0.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction0Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.Objects; @@ -176,26 +178,18 @@ default Function0 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function0 that wraps this CheckedFunction0 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function0 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction0 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function0 that wraps this CheckedFunction0 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function0 that throws a {@code Throwable}. */ default Function0 unchecked() { - return unchecked(IllegalStateException::new); + return () -> { + try { + return apply(); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -212,4 +206,13 @@ default CheckedFunction0 andThen(CheckedFunction1 return () -> after.apply(apply()); } +} + +interface CheckedFunction0Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction1.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction1.java index 5540c93317..e736d6e9ab 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction1.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction1.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction1Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -195,26 +197,18 @@ default Function1 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function1 that wraps this CheckedFunction1 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function1 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction1 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function1 that wraps this CheckedFunction1 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function1 that throws a {@code Throwable}. */ default Function1 unchecked() { - return unchecked(IllegalStateException::new); + return (t1) -> { + try { + return apply(t1); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -244,4 +238,13 @@ default CheckedFunction1 compose(CheckedFunction1 apply(before.apply(v)); } +} + +interface CheckedFunction1Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction2.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction2.java index 3e20de774d..4a05400585 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction2.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction2.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction2Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -203,26 +205,18 @@ default Function2 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function2 that wraps this CheckedFunction2 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function2 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction2 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function2 that wraps this CheckedFunction2 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function2 that throws a {@code Throwable}. */ default Function2 unchecked() { - return unchecked(IllegalStateException::new); + return (t1, t2) -> { + try { + return apply(t1, t2); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -239,4 +233,13 @@ default CheckedFunction2 andThen(CheckedFunction1 after.apply(apply(t1, t2)); } +} + +interface CheckedFunction2Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction3.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction3.java index bcccca1f42..6a52867390 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction3.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction3.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction3Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -220,26 +222,18 @@ default Function3 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function3 that wraps this CheckedFunction3 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function3 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction3 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function3 that wraps this CheckedFunction3 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function3 that throws a {@code Throwable}. */ default Function3 unchecked() { - return unchecked(IllegalStateException::new); + return (t1, t2, t3) -> { + try { + return apply(t1, t2, t3); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -256,4 +250,13 @@ default CheckedFunction3 andThen(CheckedFunction1 after.apply(apply(t1, t2, t3)); } +} + +interface CheckedFunction3Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction4.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction4.java index a6bb301660..e9db0242d5 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction4.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction4.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction4Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -239,26 +241,18 @@ default Function4 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function4 that wraps this CheckedFunction4 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function4 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction4 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function4 that wraps this CheckedFunction4 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function4 that throws a {@code Throwable}. */ default Function4 unchecked() { - return unchecked(IllegalStateException::new); + return (t1, t2, t3, t4) -> { + try { + return apply(t1, t2, t3, t4); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -275,4 +269,13 @@ default CheckedFunction4 andThen(CheckedFunction1 after.apply(apply(t1, t2, t3, t4)); } +} + +interface CheckedFunction4Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction5.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction5.java index 870ee82213..3287747d12 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction5.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction5.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction5Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -259,26 +261,18 @@ default Function5 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function5 that wraps this CheckedFunction5 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function5 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction5 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function5 that wraps this CheckedFunction5 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function5 that throws a {@code Throwable}. */ default Function5 unchecked() { - return unchecked(IllegalStateException::new); + return (t1, t2, t3, t4, t5) -> { + try { + return apply(t1, t2, t3, t4, t5); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -295,4 +289,13 @@ default CheckedFunction5 andThen(CheckedFunction1 after.apply(apply(t1, t2, t3, t4, t5)); } +} + +interface CheckedFunction5Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction6.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction6.java index 446abfa83f..f9e86f56e5 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction6.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction6.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction6Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -280,26 +282,18 @@ default Function6 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function6 that wraps this CheckedFunction6 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function6 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction6 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function6 that wraps this CheckedFunction6 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function6 that throws a {@code Throwable}. */ default Function6 unchecked() { - return unchecked(IllegalStateException::new); + return (t1, t2, t3, t4, t5, t6) -> { + try { + return apply(t1, t2, t3, t4, t5, t6); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -316,4 +310,13 @@ default CheckedFunction6 andThen(CheckedFunction1 return (t1, t2, t3, t4, t5, t6) -> after.apply(apply(t1, t2, t3, t4, t5, t6)); } +} + +interface CheckedFunction6Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction7.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction7.java index bc4d37b8b2..a830028c68 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction7.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction7.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction7Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -302,26 +304,18 @@ default Function7 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function7 that wraps this CheckedFunction7 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function7 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction7 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function7 that wraps this CheckedFunction7 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function7 that throws a {@code Throwable}. */ default Function7 unchecked() { - return unchecked(IllegalStateException::new); + return (t1, t2, t3, t4, t5, t6, t7) -> { + try { + return apply(t1, t2, t3, t4, t5, t6, t7); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -338,4 +332,13 @@ default CheckedFunction7 andThen(CheckedFunct return (t1, t2, t3, t4, t5, t6, t7) -> after.apply(apply(t1, t2, t3, t4, t5, t6, t7)); } +} + +interface CheckedFunction7Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/CheckedFunction8.java b/vavr/src-gen/main/java/io/vavr/CheckedFunction8.java index 783488652a..591b9b54a0 100644 --- a/vavr/src-gen/main/java/io/vavr/CheckedFunction8.java +++ b/vavr/src-gen/main/java/io/vavr/CheckedFunction8.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.CheckedFunction8Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -325,26 +327,18 @@ default Function8 recover(Functionsneaky throw if an exceptions occurs when applying the function. * - * @param exceptionMapper the function that convert function {@link Throwable} into subclass of {@link RuntimeException} - * @return a new Function8 that wraps this CheckedFunction8 by throwing a {@code RuntimeException} issued by the given {@code exceptionMapper} in the case of a failure - */ - default Function8 unchecked(Function exceptionMapper) { - return recover(throwable -> { - throw exceptionMapper.apply(throwable); - }); - } - - /** - * Return unchecked function that will return this CheckedFunction8 result in correct case and throw exception - * wrapped by {@link IllegalStateException} in case of throwable. - * - * @return a new Function8 that wraps this CheckedFunction8 by throwing an {@code IllegalStateException} in the case of a failure + * @return a new Function8 that throws a {@code Throwable}. */ default Function8 unchecked() { - return unchecked(IllegalStateException::new); + return (t1, t2, t3, t4, t5, t6, t7, t8) -> { + try { + return apply(t1, t2, t3, t4, t5, t6, t7, t8); + } catch(Throwable t) { + return sneakyThrow(t); + } + }; } /** @@ -361,4 +355,13 @@ default CheckedFunction8 andThen(CheckedF return (t1, t2, t3, t4, t5, t6, t7, t8) -> after.apply(apply(t1, t2, t3, t4, t5, t6, t7, t8)); } +} + +interface CheckedFunction8Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function0.java b/vavr/src-gen/main/java/io/vavr/Function0.java index 80eae6b1ff..942557e12d 100644 --- a/vavr/src-gen/main/java/io/vavr/Function0.java +++ b/vavr/src-gen/main/java/io/vavr/Function0.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function0Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.Objects; @@ -178,4 +180,13 @@ default Function0 andThen(Function after) { return () -> after.apply(apply()); } +} + +interface Function0Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function1.java b/vavr/src-gen/main/java/io/vavr/Function1.java index 5e49dfda87..1f4dc54b54 100644 --- a/vavr/src-gen/main/java/io/vavr/Function1.java +++ b/vavr/src-gen/main/java/io/vavr/Function1.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function1Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -223,4 +225,13 @@ default Function1 compose(Function before) { Objects.requireNonNull(before, "before is null"); return v -> apply(before.apply(v)); } +} + +interface Function1Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function2.java b/vavr/src-gen/main/java/io/vavr/Function2.java index 8d140aa58c..6cad211b51 100644 --- a/vavr/src-gen/main/java/io/vavr/Function2.java +++ b/vavr/src-gen/main/java/io/vavr/Function2.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function2Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -195,4 +197,13 @@ default Function2 andThen(Function after) return (t1, t2) -> after.apply(apply(t1, t2)); } +} + +interface Function2Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function3.java b/vavr/src-gen/main/java/io/vavr/Function3.java index f850a64472..e98211d7f1 100644 --- a/vavr/src-gen/main/java/io/vavr/Function3.java +++ b/vavr/src-gen/main/java/io/vavr/Function3.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function3Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -212,4 +214,13 @@ default Function3 andThen(Function af return (t1, t2, t3) -> after.apply(apply(t1, t2, t3)); } +} + +interface Function3Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function4.java b/vavr/src-gen/main/java/io/vavr/Function4.java index 496771afb9..b3fa333d4f 100644 --- a/vavr/src-gen/main/java/io/vavr/Function4.java +++ b/vavr/src-gen/main/java/io/vavr/Function4.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function4Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -231,4 +233,13 @@ default Function4 andThen(Function after.apply(apply(t1, t2, t3, t4)); } +} + +interface Function4Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function5.java b/vavr/src-gen/main/java/io/vavr/Function5.java index 79bb0b2430..7b47fcc3bd 100644 --- a/vavr/src-gen/main/java/io/vavr/Function5.java +++ b/vavr/src-gen/main/java/io/vavr/Function5.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function5Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -251,4 +253,13 @@ default Function5 andThen(Function after.apply(apply(t1, t2, t3, t4, t5)); } +} + +interface Function5Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function6.java b/vavr/src-gen/main/java/io/vavr/Function6.java index 5b353a5f5c..1ffdd70bc8 100644 --- a/vavr/src-gen/main/java/io/vavr/Function6.java +++ b/vavr/src-gen/main/java/io/vavr/Function6.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function6Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -272,4 +274,13 @@ default Function6 andThen(Function after.apply(apply(t1, t2, t3, t4, t5, t6)); } +} + +interface Function6Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function7.java b/vavr/src-gen/main/java/io/vavr/Function7.java index d490ab04f4..e6f2ac1762 100644 --- a/vavr/src-gen/main/java/io/vavr/Function7.java +++ b/vavr/src-gen/main/java/io/vavr/Function7.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function7Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -294,4 +296,13 @@ default Function7 andThen(Function after.apply(apply(t1, t2, t3, t4, t5, t6, t7)); } +} + +interface Function7Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/main/java/io/vavr/Function8.java b/vavr/src-gen/main/java/io/vavr/Function8.java index dfb54010c0..ddd2b2e119 100644 --- a/vavr/src-gen/main/java/io/vavr/Function8.java +++ b/vavr/src-gen/main/java/io/vavr/Function8.java @@ -10,6 +10,8 @@ G E N E R A T O R C R A F T E D \*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +import static io.vavr.Function8Module.sneakyThrow; + import io.vavr.control.Option; import io.vavr.control.Try; import java.util.HashMap; @@ -317,4 +319,13 @@ default Function8 andThen(Function after.apply(apply(t1, t2, t3, t4, t5, t6, t7, t8)); } +} + +interface Function8Module { + + // DEV-NOTE: we do not plan to expose this as public API + @SuppressWarnings("unchecked") + static R sneakyThrow(Throwable t) throws T { + throw (T) t; + } } \ No newline at end of file diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction0Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction0Test.java index 1864e1cde3..35458b2101 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction0Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction0Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -137,11 +138,11 @@ public void shouldUncheckedWork() { assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) - public void shouldUncheckedThrowIllegalState() { + @Test(expected = NoSuchAlgorithmException.class) + public void shouldThrowCheckedExceptionWhenUnchecked() { CheckedFunction0 digest = () -> MessageDigest.getInstance("Unknown"); Function0 unchecked = digest.unchecked(); - unchecked.apply(); + unchecked.apply(); // Look ma, we throw an undeclared checked exception! } @Test diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction1Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction1Test.java index 24f43a6480..4c9a7ebb04 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction1Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction1Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -116,8 +117,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function1 recover = digest.recover(throwable -> (s1) -> null); - MessageDigest md5 = recover.apply("MD5"); + final Function1 recover = digest.recover(throwable -> (s1) -> null); + final MessageDigest md5 = recover.apply("MD5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -126,12 +127,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function1 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("MD5"); + final Function1 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("MD5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function1.liftTry(recover).apply("Unknown"); + final Try unknown = Function1.liftTry(recover).apply("Unknown"); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -140,28 +141,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function1 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("MD5"); + final Function1 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("MD5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function1 unchecked = digest.unchecked(); - unchecked.apply("Unknown"); + final Function1 unchecked = digest.unchecked(); + unchecked.apply("Unknown"); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function1> liftTry = CheckedFunction1.liftTry(digest); - Try md5 = liftTry.apply("MD5"); + final Function1> liftTry = CheckedFunction1.liftTry(digest); + final Try md5 = liftTry.apply("MD5"); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("Unknown"); + final Try unknown = liftTry.apply("Unknown"); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction2Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction2Test.java index e8b72993a4..3067b10213 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction2Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction2Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -115,8 +116,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function2 recover = digest.recover(throwable -> (s1, s2) -> null); - MessageDigest md5 = recover.apply("M", "D5"); + final Function2 recover = digest.recover(throwable -> (s1, s2) -> null); + final MessageDigest md5 = recover.apply("M", "D5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -125,12 +126,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function2 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("M", "D5"); + final Function2 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("M", "D5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function2.liftTry(recover).apply("U", "nknown"); + final Try unknown = Function2.liftTry(recover).apply("U", "nknown"); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -139,28 +140,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function2 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("M", "D5"); + final Function2 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("M", "D5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function2 unchecked = digest.unchecked(); - unchecked.apply("U", "nknown"); + final Function2 unchecked = digest.unchecked(); + unchecked.apply("U", "nknown"); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function2> liftTry = CheckedFunction2.liftTry(digest); - Try md5 = liftTry.apply("M", "D5"); + final Function2> liftTry = CheckedFunction2.liftTry(digest); + final Try md5 = liftTry.apply("M", "D5"); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("U", "nknown"); + final Try unknown = liftTry.apply("U", "nknown"); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction3Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction3Test.java index 83b1397db3..5a653aa44b 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction3Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction3Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -116,8 +117,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function3 recover = digest.recover(throwable -> (s1, s2, s3) -> null); - MessageDigest md5 = recover.apply("M", "D", "5"); + final Function3 recover = digest.recover(throwable -> (s1, s2, s3) -> null); + final MessageDigest md5 = recover.apply("M", "D", "5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -126,12 +127,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function3 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("M", "D", "5"); + final Function3 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("M", "D", "5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function3.liftTry(recover).apply("U", "n", "known"); + final Try unknown = Function3.liftTry(recover).apply("U", "n", "known"); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -140,28 +141,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function3 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("M", "D", "5"); + final Function3 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("M", "D", "5"); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function3 unchecked = digest.unchecked(); - unchecked.apply("U", "n", "known"); + final Function3 unchecked = digest.unchecked(); + unchecked.apply("U", "n", "known"); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function3> liftTry = CheckedFunction3.liftTry(digest); - Try md5 = liftTry.apply("M", "D", "5"); + final Function3> liftTry = CheckedFunction3.liftTry(digest); + final Try md5 = liftTry.apply("M", "D", "5"); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("U", "n", "known"); + final Try unknown = liftTry.apply("U", "n", "known"); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction4Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction4Test.java index bd0443cf28..70200dd663 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction4Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction4Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -117,8 +118,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function4 recover = digest.recover(throwable -> (s1, s2, s3, s4) -> null); - MessageDigest md5 = recover.apply("M", "D", "5", ""); + final Function4 recover = digest.recover(throwable -> (s1, s2, s3, s4) -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -127,12 +128,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function4 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("M", "D", "5", ""); + final Function4 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function4.liftTry(recover).apply("U", "n", "k", "nown"); + final Try unknown = Function4.liftTry(recover).apply("U", "n", "k", "nown"); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -141,28 +142,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function4 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("M", "D", "5", ""); + final Function4 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("M", "D", "5", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function4 unchecked = digest.unchecked(); - unchecked.apply("U", "n", "k", "nown"); + final Function4 unchecked = digest.unchecked(); + unchecked.apply("U", "n", "k", "nown"); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function4> liftTry = CheckedFunction4.liftTry(digest); - Try md5 = liftTry.apply("M", "D", "5", ""); + final Function4> liftTry = CheckedFunction4.liftTry(digest); + final Try md5 = liftTry.apply("M", "D", "5", ""); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("U", "n", "k", "nown"); + final Try unknown = liftTry.apply("U", "n", "k", "nown"); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction5Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction5Test.java index 215bb8d540..b4d2a290fc 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction5Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction5Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -118,8 +119,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function5 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5) -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", ""); + final Function5 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5) -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -128,12 +129,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function5 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", ""); + final Function5 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function5.liftTry(recover).apply("U", "n", "k", "n", "own"); + final Try unknown = Function5.liftTry(recover).apply("U", "n", "k", "n", "own"); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -142,28 +143,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function5 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("M", "D", "5", "", ""); + final Function5 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("M", "D", "5", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function5 unchecked = digest.unchecked(); - unchecked.apply("U", "n", "k", "n", "own"); + final Function5 unchecked = digest.unchecked(); + unchecked.apply("U", "n", "k", "n", "own"); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function5> liftTry = CheckedFunction5.liftTry(digest); - Try md5 = liftTry.apply("M", "D", "5", "", ""); + final Function5> liftTry = CheckedFunction5.liftTry(digest); + final Try md5 = liftTry.apply("M", "D", "5", "", ""); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("U", "n", "k", "n", "own"); + final Try unknown = liftTry.apply("U", "n", "k", "n", "own"); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction6Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction6Test.java index ca272b278a..ec5064f5a2 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction6Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction6Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -119,8 +120,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function6 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5, s6) -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", "", ""); + final Function6 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5, s6) -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -129,12 +130,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function6 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", "", ""); + final Function6 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function6.liftTry(recover).apply("U", "n", "k", "n", "o", "wn"); + final Try unknown = Function6.liftTry(recover).apply("U", "n", "k", "n", "o", "wn"); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -143,28 +144,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function6 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("M", "D", "5", "", "", ""); + final Function6 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("M", "D", "5", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function6 unchecked = digest.unchecked(); - unchecked.apply("U", "n", "k", "n", "o", "wn"); + final Function6 unchecked = digest.unchecked(); + unchecked.apply("U", "n", "k", "n", "o", "wn"); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function6> liftTry = CheckedFunction6.liftTry(digest); - Try md5 = liftTry.apply("M", "D", "5", "", "", ""); + final Function6> liftTry = CheckedFunction6.liftTry(digest); + final Try md5 = liftTry.apply("M", "D", "5", "", "", ""); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("U", "n", "k", "n", "o", "wn"); + final Try unknown = liftTry.apply("U", "n", "k", "n", "o", "wn"); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction7Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction7Test.java index 84d8e5e6be..eb5021b99b 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction7Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction7Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -120,8 +121,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function7 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5, s6, s7) -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", ""); + final Function7 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5, s6, s7) -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -130,12 +131,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function7 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", ""); + final Function7 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function7.liftTry(recover).apply("U", "n", "k", "n", "o", "w", "n"); + final Try unknown = Function7.liftTry(recover).apply("U", "n", "k", "n", "o", "w", "n"); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -144,28 +145,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function7 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("M", "D", "5", "", "", "", ""); + final Function7 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("M", "D", "5", "", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function7 unchecked = digest.unchecked(); - unchecked.apply("U", "n", "k", "n", "o", "w", "n"); + final Function7 unchecked = digest.unchecked(); + unchecked.apply("U", "n", "k", "n", "o", "w", "n"); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function7> liftTry = CheckedFunction7.liftTry(digest); - Try md5 = liftTry.apply("M", "D", "5", "", "", "", ""); + final Function7> liftTry = CheckedFunction7.liftTry(digest); + final Try md5 = liftTry.apply("M", "D", "5", "", "", "", ""); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("U", "n", "k", "n", "o", "w", "n"); + final Try unknown = liftTry.apply("U", "n", "k", "n", "o", "w", "n"); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available"); diff --git a/vavr/src-gen/test/java/io/vavr/CheckedFunction8Test.java b/vavr/src-gen/test/java/io/vavr/CheckedFunction8Test.java index e61a958548..54c80c7485 100644 --- a/vavr/src-gen/test/java/io/vavr/CheckedFunction8Test.java +++ b/vavr/src-gen/test/java/io/vavr/CheckedFunction8Test.java @@ -15,6 +15,7 @@ import io.vavr.control.Try; import java.lang.CharSequence; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -121,8 +122,8 @@ public void shouldRecognizeMemoizedFunctions() { @Test public void shouldRecover() { - Function8 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5, s6, s7, s8) -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", "", ""); + final Function8 recover = digest.recover(throwable -> (s1, s2, s3, s4, s5, s6, s7, s8) -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); @@ -131,12 +132,12 @@ public void shouldRecover() { @Test public void shouldRecoverNonNull() { - Function8 recover = digest.recover(throwable -> null); - MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", "", ""); + final Function8 recover = digest.recover(throwable -> null); + final MessageDigest md5 = recover.apply("M", "D", "5", "", "", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); - Try unknown = Function8.liftTry(recover).apply("U", "n", "k", "n", "o", "w", "n", ""); + final Try unknown = Function8.liftTry(recover).apply("U", "n", "k", "n", "o", "w", "n", ""); assertThat(unknown).isNotNull(); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull().isInstanceOf(NullPointerException.class); @@ -145,28 +146,28 @@ public void shouldRecoverNonNull() { @Test public void shouldUncheckedWork() { - Function8 unchecked = digest.unchecked(); - MessageDigest md5 = unchecked.apply("M", "D", "5", "", "", "", "", ""); + final Function8 unchecked = digest.unchecked(); + final MessageDigest md5 = unchecked.apply("M", "D", "5", "", "", "", "", ""); assertThat(md5).isNotNull(); assertThat(md5.getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.getDigestLength()).isEqualTo(16); } - @Test(expected = IllegalStateException.class) + @Test(expected = NoSuchAlgorithmException.class) public void shouldUncheckedThrowIllegalState() { - Function8 unchecked = digest.unchecked(); - unchecked.apply("U", "n", "k", "n", "o", "w", "n", ""); + final Function8 unchecked = digest.unchecked(); + unchecked.apply("U", "n", "k", "n", "o", "w", "n", ""); // Look ma, we throw an undeclared checked exception! } @Test public void shouldLiftTryPartialFunction() { - Function8> liftTry = CheckedFunction8.liftTry(digest); - Try md5 = liftTry.apply("M", "D", "5", "", "", "", "", ""); + final Function8> liftTry = CheckedFunction8.liftTry(digest); + final Try md5 = liftTry.apply("M", "D", "5", "", "", "", "", ""); assertThat(md5.isSuccess()).isTrue(); assertThat(md5.get()).isNotNull(); assertThat(md5.get().getAlgorithm()).isEqualToIgnoringCase("MD5"); assertThat(md5.get().getDigestLength()).isEqualTo(16); - Try unknown = liftTry.apply("U", "n", "k", "n", "o", "w", "n", ""); + final Try unknown = liftTry.apply("U", "n", "k", "n", "o", "w", "n", ""); assertThat(unknown.isFailure()).isTrue(); assertThat(unknown.getCause()).isNotNull(); assertThat(unknown.getCause().getMessage()).isEqualToIgnoringCase("Unknown MessageDigest not available");