diff --git a/src/main/java/com/plugatar/jkscope/JKScope.java b/src/main/java/com/plugatar/jkscope/JKScope.java index 8cd6745..1bccf55 100644 --- a/src/main/java/com/plugatar/jkscope/JKScope.java +++ b/src/main/java/com/plugatar/jkscope/JKScope.java @@ -137,33 +137,33 @@ public interface JKScope> extends BaseScope { @Override default V also(final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(uncheckedCast(this)); + ThConsumer.unchecked(block).accept(uncheckedCast(this)); return uncheckedCast(this); } @Override default V letIt(final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(uncheckedCast(this)); + ThConsumer.unchecked(block).accept(uncheckedCast(this)); return uncheckedCast(this); } @Override default R letOut(final ThFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(uncheckedCast(this)); + return ThFunction.unchecked(block).apply(uncheckedCast(this)); } @Override default Opt letOpt(final ThFunction block) { blockArgNotNull(block); - return Opt.of(block.asUnchecked().apply(uncheckedCast(this))); + return Opt.of(ThFunction.unchecked(block).apply(uncheckedCast(this))); } @Override default Opt takeIf(final ThPredicate block) { blockArgNotNull(block); - return block.asUnchecked().test(uncheckedCast(this)) + return ThPredicate.unchecked(block).test(uncheckedCast(this)) ? Opt.of(uncheckedCast(this)) : Opt.empty(); } @@ -171,7 +171,7 @@ default Opt takeIf(final ThPredicate block) { @Override default Opt takeUnless(final ThPredicate block) { blockArgNotNull(block); - return block.asUnchecked().test(uncheckedCast(this)) + return ThPredicate.unchecked(block).test(uncheckedCast(this)) ? Opt.empty() : Opt.of(uncheckedCast(this)); } @@ -189,7 +189,7 @@ default Opt takeUnless(final ThPredicate block) { */ static void run(final ThRunnable block) { blockArgNotNull(block); - block.asUnchecked().run(); + ThRunnable.unchecked(block).run(); } /** @@ -208,7 +208,7 @@ static void run(final ThRunnable block) { static void runCatching(final ThRunnable block) { blockArgNotNull(block); try { - block.asUnchecked().run(); + block.run(); } catch (final Throwable ignored) { } } @@ -229,7 +229,7 @@ static void runRec(final ThConsumer, ?> block) { blockArgNotNull(block); final AtomicReference> selfRef = new AtomicReference<>(); selfRef.set(() -> block.accept(selfRef.get())); - block.asUnchecked().accept(selfRef.get()); + ThConsumer.unchecked(block).accept(selfRef.get()); } /** @@ -248,7 +248,7 @@ static void runRec(final ThConsumer, ?> block) { static void with(final V value, final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThConsumer.unchecked(block).accept(value); } /** @@ -266,7 +266,7 @@ static void with(final V value, static void withInt(final int value, final ThIntConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThIntConsumer.unchecked(block).accept(value); } /** @@ -284,7 +284,7 @@ static void withInt(final int value, static void withLong(final long value, final ThLongConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThLongConsumer.unchecked(block).accept(value); } /** @@ -302,7 +302,7 @@ static void withLong(final long value, static void withDouble(final double value, final ThDoubleConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThDoubleConsumer.unchecked(block).accept(value); } /** @@ -319,11 +319,11 @@ static void withDouble(final double value, static void withResource(final V value, final ThConsumer block) { blockArgNotNull(block); - ((ThBiConsumer, Throwable>) (v, b) -> { + ThBiConsumer.>unchecked((v, b) -> { try (final V resource = v) { b.accept(resource); } - }).asUnchecked().accept(value, block); + }).accept(value, block); } /** @@ -345,7 +345,7 @@ static void with(final V1 value1, final V2 value2, final ThBiConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value1, value2); + ThBiConsumer.unchecked(block).accept(value1, value2); } /** @@ -370,7 +370,7 @@ static void with(final V1 value1, final V3 value3, final ThTriConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value1, value2, value3); + ThTriConsumer.unchecked(block).accept(value1, value2, value3); } /** @@ -418,7 +418,7 @@ static Opt letNonNull(final V value) { */ static V let(final ThSupplier block) { blockArgNotNull(block); - return block.asUnchecked().get(); + return ThSupplier.unchecked(block).get(); } /** @@ -436,7 +436,7 @@ static V let(final ThSupplier block) { */ static int letInt(final ThIntSupplier block) { blockArgNotNull(block); - return block.asUnchecked().get(); + return ThIntSupplier.unchecked(block).get(); } /** @@ -454,7 +454,7 @@ static int letInt(final ThIntSupplier block) { */ static long letLong(final ThLongSupplier block) { blockArgNotNull(block); - return block.asUnchecked().get(); + return ThLongSupplier.unchecked(block).get(); } /** @@ -472,7 +472,7 @@ static long letLong(final ThLongSupplier block) { */ static double letDouble(final ThDoubleSupplier block) { blockArgNotNull(block); - return block.asUnchecked().get(); + return ThDoubleSupplier.unchecked(block).get(); } /** @@ -492,7 +492,7 @@ static double letDouble(final ThDoubleSupplier block) { static V let(final V value, final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThConsumer.unchecked(block).accept(value); return value; } @@ -512,7 +512,7 @@ static V let(final V value, static int letInt(final int value, final ThIntConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThIntConsumer.unchecked(block).accept(value); return value; } @@ -532,7 +532,7 @@ static int letInt(final int value, static long letLong(final long value, final ThLongConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThLongConsumer.unchecked(block).accept(value); return value; } @@ -552,7 +552,7 @@ static long letLong(final long value, static double letDouble(final double value, final ThDoubleConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(value); + ThDoubleConsumer.unchecked(block).accept(value); return value; } @@ -578,7 +578,7 @@ static V letRec(final V initialValue, blockArgNotNull(block); final AtomicReference> selfRef = new AtomicReference<>(); selfRef.set(v -> block.apply(v, selfRef.get())); - return block.asUnchecked().apply(initialValue, selfRef.get()); + return ThBiFunction.unchecked(block).apply(initialValue, selfRef.get()); } /** @@ -602,7 +602,7 @@ static int letIntRec(final int initialValue, blockArgNotNull(block); final AtomicReference> selfRef = new AtomicReference<>(); selfRef.set(v -> block.apply(v, selfRef.get())); - return block.asUnchecked().apply(initialValue, selfRef.get()); + return ThIntObjToIntFunction.unchecked(block).apply(initialValue, selfRef.get()); } /** @@ -626,7 +626,7 @@ static long letLongRec(final long initialValue, blockArgNotNull(block); final AtomicReference> selfRef = new AtomicReference<>(); selfRef.set(v -> block.apply(v, selfRef.get())); - return block.asUnchecked().apply(initialValue, selfRef.get()); + return ThLongObjToLongFunction.unchecked(block).apply(initialValue, selfRef.get()); } /** @@ -650,7 +650,7 @@ static double letDoubleRec(final double initialValue, blockArgNotNull(block); final AtomicReference> selfRef = new AtomicReference<>(); selfRef.set(v -> block.apply(v, selfRef.get())); - return block.asUnchecked().apply(initialValue, selfRef.get()); + return ThDoubleObjToDoubleFunction.unchecked(block).apply(initialValue, selfRef.get()); } /** @@ -672,7 +672,7 @@ static double letDoubleRec(final double initialValue, static R letWith(final V value, final ThFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(value); + return ThFunction.unchecked(block).apply(value); } /** @@ -692,7 +692,7 @@ static R letWith(final V value, static int letIntWith(final V value, final ThToIntFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(value); + return ThToIntFunction.unchecked(block).apply(value); } /** @@ -712,7 +712,7 @@ static int letIntWith(final V value, static long letLongWith(final V value, final ThToLongFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(value); + return ThToLongFunction.unchecked(block).apply(value); } /** @@ -732,7 +732,7 @@ static long letLongWith(final V value, static double letDoubleWith(final V value, final ThToDoubleFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(value); + return ThToDoubleFunction.unchecked(block).apply(value); } /** @@ -751,11 +751,11 @@ static double letDoubleWith(final V value, static R letWithResource(final V value, final ThFunction block) { blockArgNotNull(block); - return ((ThBiFunction, R, Throwable>) (v, b) -> { + return ThBiFunction., R>unchecked((v, b) -> { try (final V resource = v) { return b.apply(resource); } - }).asUnchecked().apply(value, block); + }).apply(value, block); } /** @@ -781,7 +781,7 @@ static R letWith(final V1 value1, final V2 value2, final ThBiFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(value1, value2); + return ThBiFunction.unchecked(block).apply(value1, value2); } /** @@ -811,7 +811,7 @@ static R letWith(final V1 value1, final V3 value3, final ThTriFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(value1, value2, value3); + return ThTriFunction.unchecked(block).apply(value1, value2, value3); } /** diff --git a/src/main/java/com/plugatar/jkscope/Lazy.java b/src/main/java/com/plugatar/jkscope/Lazy.java index 09a2de6..071798b 100644 --- a/src/main/java/com/plugatar/jkscope/Lazy.java +++ b/src/main/java/com/plugatar/jkscope/Lazy.java @@ -38,34 +38,34 @@ public interface Lazy extends ThSupplier, BaseScope also(final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(this.get()); + ThConsumer.unchecked(block).accept(this.get()); return this; } @Override default Lazy letIt(final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(this.get()); + ThConsumer.unchecked(block).accept(this.get()); return this; } @Override default R letOut(final ThFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(this.get()); + return ThFunction.unchecked(block).apply(this.get()); } @Override default Opt letOpt(final ThFunction block) { blockArgNotNull(block); - return Opt.of(block.asUnchecked().apply(this.get())); + return Opt.of(ThFunction.unchecked(block).apply(this.get())); } @Override default Opt takeIf(final ThPredicate block) { blockArgNotNull(block); final V v = this.get(); - return block.asUnchecked().test(v) + return ThPredicate.unchecked(block).test(v) ? Opt.of(v) : Opt.empty(); } @@ -74,7 +74,7 @@ default Opt takeIf(final ThPredicate block) { default Opt takeUnless(final ThPredicate block) { blockArgNotNull(block); final V v = this.get(); - return block.asUnchecked().test(v) + return ThPredicate.unchecked(block).test(v) ? Opt.empty() : Opt.of(v); } @@ -210,7 +210,7 @@ public V get() { if (v2 != UNINITIALIZED_VALUE) { return uncheckedCast(v2); } - final V newValue = this.initializer.asUnchecked().get(); + final V newValue = ThSupplier.unchecked(this.initializer).get(); this.value = newValue; this.initializer = null; return newValue; @@ -264,7 +264,7 @@ public V get() { } final ThSupplier init = this.initializer; if (init != null) { - final V newValue = init.asUnchecked().get(); + final V newValue = ThSupplier.unchecked(init).get(); if (VALUE_UPDATER.compareAndSet(this, UNINITIALIZED_VALUE, newValue)) { this.initializer = null; return newValue; @@ -318,7 +318,7 @@ public V get() { } final ThSupplier init = this.initializer; if (init != null) { - final V newValue = init.asUnchecked().get(); + final V newValue = ThSupplier.unchecked(init).get(); this.value = newValue; this.initializer = null; return newValue; diff --git a/src/main/java/com/plugatar/jkscope/Opt.java b/src/main/java/com/plugatar/jkscope/Opt.java index f37c57c..32b8803 100644 --- a/src/main/java/com/plugatar/jkscope/Opt.java +++ b/src/main/java/com/plugatar/jkscope/Opt.java @@ -165,33 +165,33 @@ private Of(final V value) { @Override public Opt also(final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(this.value); + ThConsumer.unchecked(block).accept(this.value); return this; } @Override public Opt letIt(final ThConsumer block) { blockArgNotNull(block); - block.asUnchecked().accept(this.value); + ThConsumer.unchecked(block).accept(this.value); return this; } @Override public R letOut(final ThFunction block) { blockArgNotNull(block); - return block.asUnchecked().apply(this.value); + return ThFunction.unchecked(block).apply(this.value); } @Override public Opt letOpt(final ThFunction block) { blockArgNotNull(block); - return Opt.of(block.asUnchecked().apply(this.value)); + return Opt.of(ThFunction.unchecked(block).apply(this.value)); } @Override public Opt takeIf(final ThPredicate block) { blockArgNotNull(block); - return block.asUnchecked().test(this.value) + return ThPredicate.unchecked(block).test(this.value) ? this : Opt.empty(); } @@ -199,7 +199,7 @@ public Opt takeIf(final ThPredicate block) { @Override public Opt takeUnless(final ThPredicate block) { blockArgNotNull(block); - return block.asUnchecked().test(this.value) + return ThPredicate.unchecked(block).test(this.value) ? Opt.empty() : this; } @@ -320,9 +320,7 @@ public Opt takeNonNull() { @Override public Opt throwIfEmpty(final ThSupplier block) { blockArgNotNull(block); - return ((ThFunction, Opt, ?>) it -> { throw it.get(); }) - .asUnchecked() - .apply(block); + return ThFunction., Opt>unchecked(it -> { throw it.get(); }).apply(block); } @Override @@ -348,15 +346,13 @@ public V orNull() { @Override public V orElseGet(final ThSupplier block) { blockArgNotNull(block); - return block.asUnchecked().get(); + return ThSupplier.unchecked(block).get(); } @Override public V orElseThrow(final ThSupplier block) { blockArgNotNull(block); - return ((ThFunction, V, ?>) it -> { throw it.get(); }) - .asUnchecked() - .apply(block); + return ThFunction., V>unchecked(it -> { throw it.get(); }).apply(block); } @Override diff --git a/src/main/java/com/plugatar/jkscope/function/ThBiConsumer.java b/src/main/java/com/plugatar/jkscope/function/ThBiConsumer.java index 94cb4f8..191761e 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThBiConsumer.java +++ b/src/main/java/com/plugatar/jkscope/function/ThBiConsumer.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.BiConsumer} specialization that might throw an exception. * @@ -36,12 +39,16 @@ public interface ThBiConsumer { void accept(T t, U u) throws E; /** - * Returns this consumer as an unchecked consumer. + * Returns given consumer as an unchecked consumer. * + * @param origin the origin consumer + * @param the type of the first input argument + * @param the type of the second input argument * @return unchecked consumer + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThBiConsumer asUnchecked() { - return (ThBiConsumer) this; + static ThBiConsumer unchecked(final ThBiConsumer origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThBiFunction.java b/src/main/java/com/plugatar/jkscope/function/ThBiFunction.java index 7c58836..ad30c0a 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThBiFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThBiFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.BiFunction} specialization that might throw an exception. * @@ -38,12 +41,17 @@ public interface ThBiFunction { R apply(T t, U u) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the first input argument + * @param the type of the second input argument + * @param the type of the result * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThBiFunction asUnchecked() { - return (ThBiFunction) this; + static ThBiFunction unchecked(final ThBiFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThConsumer.java b/src/main/java/com/plugatar/jkscope/function/ThConsumer.java index 2c28e5c..73cc040 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThConsumer.java +++ b/src/main/java/com/plugatar/jkscope/function/ThConsumer.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Consumer} specialization that might throw an exception. * @@ -34,12 +37,15 @@ public interface ThConsumer { void accept(T t) throws E; /** - * Returns this consumer as an unchecked consumer. + * Returns given consumer as an unchecked consumer. * + * @param origin the origin consumer + * @param the type of the input argument * @return unchecked consumer + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThConsumer asUnchecked() { - return (ThConsumer) this; + static ThConsumer unchecked(final ThConsumer origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThDoubleConsumer.java b/src/main/java/com/plugatar/jkscope/function/ThDoubleConsumer.java index f1e9404..0cd53de 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThDoubleConsumer.java +++ b/src/main/java/com/plugatar/jkscope/function/ThDoubleConsumer.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Consumer} specialization that that accepts an {@code double}-valued argument and might * throw an exception. @@ -34,12 +37,14 @@ public interface ThDoubleConsumer { void accept(double value) throws E; /** - * Returns this consumer as an unchecked consumer. + * Returns given consumer as an unchecked consumer. * + * @param origin the origin consumer * @return unchecked consumer + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThDoubleConsumer asUnchecked() { - return (ThDoubleConsumer) this; + static ThDoubleConsumer unchecked(final ThDoubleConsumer origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunction.java b/src/main/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunction.java index 5ef7c32..92b2b58 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that accepts an object-valued and a {@code double}-valued * argument and produces an {@code double}-valued result and might throw an exception. @@ -37,12 +40,15 @@ public interface ThDoubleObjToDoubleFunction { double apply(double value, T t) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the second input argument * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThDoubleObjToDoubleFunction asUnchecked() { - return (ThDoubleObjToDoubleFunction) this; + static ThDoubleObjToDoubleFunction unchecked(final ThDoubleObjToDoubleFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThDoubleSupplier.java b/src/main/java/com/plugatar/jkscope/function/ThDoubleSupplier.java index a7fa561..027dcc4 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThDoubleSupplier.java +++ b/src/main/java/com/plugatar/jkscope/function/ThDoubleSupplier.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Supplier} specialization that produces an {@code double}-valued result and might throw * an exception. @@ -34,12 +37,14 @@ public interface ThDoubleSupplier { double get() throws E; /** - * Returns this supplier as an unchecked supplier. + * Returns given supplier as an unchecked supplier. * - * @return unchecked runnable + * @param origin the origin supplier + * @return unchecked supplier + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThDoubleSupplier asUnchecked() { - return (ThDoubleSupplier) this; + static ThDoubleSupplier unchecked(final ThDoubleSupplier origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunction.java b/src/main/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunction.java index b9d4f43..b5bda23 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that accepts an {@code double}-valued argument and produces an * {@code double}-valued result and might throw an exception. @@ -35,12 +38,14 @@ public interface ThDoubleToDoubleFunction { double apply(double value) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThDoubleToDoubleFunction asUnchecked() { - return (ThDoubleToDoubleFunction) this; + static ThDoubleToDoubleFunction unchecked(final ThDoubleToDoubleFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThFunction.java b/src/main/java/com/plugatar/jkscope/function/ThFunction.java index f311de9..dfaf15f 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that might throw an exception. * @@ -36,12 +39,16 @@ public interface ThFunction { R apply(T t) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the input argument + * @param the type of the result * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThFunction asUnchecked() { - return (ThFunction) this; + static ThFunction unchecked(final ThFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThIntConsumer.java b/src/main/java/com/plugatar/jkscope/function/ThIntConsumer.java index 96ba73d..f26bd8a 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThIntConsumer.java +++ b/src/main/java/com/plugatar/jkscope/function/ThIntConsumer.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Consumer} specialization that that accepts an {@code int}-valued argument and might * throw an exception. @@ -34,12 +37,14 @@ public interface ThIntConsumer { void accept(int value) throws E; /** - * Returns this consumer as an unchecked consumer. + * Returns given consumer as an unchecked consumer. * + * @param origin the origin consumer * @return unchecked consumer + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThIntConsumer asUnchecked() { - return (ThIntConsumer) this; + static ThIntConsumer unchecked(final ThIntConsumer origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThIntObjToIntFunction.java b/src/main/java/com/plugatar/jkscope/function/ThIntObjToIntFunction.java index 7ce5dd3..324d353 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThIntObjToIntFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThIntObjToIntFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that accepts an object-valued and a {@code int}-valued * argument and produces an {@code int}-valued result and might throw an exception. @@ -37,12 +40,15 @@ public interface ThIntObjToIntFunction { int apply(int value, T t) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the second input argument * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThIntObjToIntFunction asUnchecked() { - return (ThIntObjToIntFunction) this; + static ThIntObjToIntFunction unchecked(final ThIntObjToIntFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThIntSupplier.java b/src/main/java/com/plugatar/jkscope/function/ThIntSupplier.java index bea468d..f4577eb 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThIntSupplier.java +++ b/src/main/java/com/plugatar/jkscope/function/ThIntSupplier.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Supplier} specialization that produces an {@code int}-valued result and might throw an * exception. @@ -34,12 +37,14 @@ public interface ThIntSupplier { int get() throws E; /** - * Returns this supplier as an unchecked supplier. + * Returns given supplier as an unchecked supplier. * - * @return unchecked runnable + * @param origin the origin supplier + * @return unchecked supplier + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThIntSupplier asUnchecked() { - return (ThIntSupplier) this; + static ThIntSupplier unchecked(final ThIntSupplier origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThIntToIntFunction.java b/src/main/java/com/plugatar/jkscope/function/ThIntToIntFunction.java index d7358e4..d62f84d 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThIntToIntFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThIntToIntFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that accepts an {@code int}-valued argument and produces an * {@code int}-valued result and might throw an exception. @@ -35,12 +38,14 @@ public interface ThIntToIntFunction { int apply(int value) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThIntToIntFunction asUnchecked() { - return (ThIntToIntFunction) this; + static ThIntToIntFunction unchecked(final ThIntToIntFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThLongConsumer.java b/src/main/java/com/plugatar/jkscope/function/ThLongConsumer.java index 981d9cc..dc2e6f2 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThLongConsumer.java +++ b/src/main/java/com/plugatar/jkscope/function/ThLongConsumer.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Consumer} specialization that that accepts an {@code long}-valued argument and might * throw an exception. @@ -34,12 +37,14 @@ public interface ThLongConsumer { void accept(long value) throws E; /** - * Returns this consumer as an unchecked consumer. + * Returns given consumer as an unchecked consumer. * + * @param origin the origin consumer * @return unchecked consumer + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThLongConsumer asUnchecked() { - return (ThLongConsumer) this; + static ThLongConsumer unchecked(final ThLongConsumer origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThLongObjToLongFunction.java b/src/main/java/com/plugatar/jkscope/function/ThLongObjToLongFunction.java index 6207c5d..834150f 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThLongObjToLongFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThLongObjToLongFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that accepts an object-valued and a {@code long}-valued * argument and produces an {@code long}-valued result and might throw an exception. @@ -37,12 +40,15 @@ public interface ThLongObjToLongFunction { long apply(long value, T t) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the second input argument * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThLongObjToLongFunction asUnchecked() { - return (ThLongObjToLongFunction) this; + static ThLongObjToLongFunction unchecked(final ThLongObjToLongFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThLongSupplier.java b/src/main/java/com/plugatar/jkscope/function/ThLongSupplier.java index 083a596..ce7b402 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThLongSupplier.java +++ b/src/main/java/com/plugatar/jkscope/function/ThLongSupplier.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Supplier} specialization that produces an {@code long}-valued result and might throw an * exception. @@ -34,12 +37,14 @@ public interface ThLongSupplier { long get() throws E; /** - * Returns this supplier as an unchecked supplier. + * Returns given supplier as an unchecked supplier. * - * @return unchecked runnable + * @param origin the origin supplier + * @return unchecked supplier + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThLongSupplier asUnchecked() { - return (ThLongSupplier) this; + static ThLongSupplier unchecked(final ThLongSupplier origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThLongToLongFunction.java b/src/main/java/com/plugatar/jkscope/function/ThLongToLongFunction.java index e716366..b20284a 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThLongToLongFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThLongToLongFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that accepts an {@code long}-valued argument and produces an * {@code long}-valued result and might throw an exception. @@ -35,12 +38,14 @@ public interface ThLongToLongFunction { long apply(long value) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThLongToLongFunction asUnchecked() { - return (ThLongToLongFunction) this; + static ThLongToLongFunction unchecked(final ThLongToLongFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThPredicate.java b/src/main/java/com/plugatar/jkscope/function/ThPredicate.java index a926cee..26a01d8 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThPredicate.java +++ b/src/main/java/com/plugatar/jkscope/function/ThPredicate.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Predicate} specialization that might throw an exception. * @@ -35,12 +38,15 @@ public interface ThPredicate { boolean test(T t) throws E; /** - * Returns this predicate as an unchecked predicate. + * Returns given supplier as an unchecked supplier. * - * @return unchecked predicate + * @param origin the origin supplier + * @param the type of the input argument + * @return unchecked supplier + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThPredicate asUnchecked() { - return (ThPredicate) this; + static ThPredicate unchecked(final ThPredicate origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThRunnable.java b/src/main/java/com/plugatar/jkscope/function/ThRunnable.java index c9e50b8..7ce8aa0 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThRunnable.java +++ b/src/main/java/com/plugatar/jkscope/function/ThRunnable.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link Runnable} specialization that might throw an exception. * @@ -32,12 +35,14 @@ public interface ThRunnable { void run() throws E; /** - * Returns this runnable as an unchecked runnable. + * Returns given runnable as an unchecked runnable. * + * @param origin the origin runnable * @return unchecked runnable + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThRunnable asUnchecked() { - return (ThRunnable) this; + static ThRunnable unchecked(final ThRunnable origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThSupplier.java b/src/main/java/com/plugatar/jkscope/function/ThSupplier.java index d036223..8025d0d 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThSupplier.java +++ b/src/main/java/com/plugatar/jkscope/function/ThSupplier.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Supplier} specialization that might throw an exception. * @@ -34,12 +37,15 @@ public interface ThSupplier { R get() throws E; /** - * Returns this supplier as an unchecked supplier. + * Returns given supplier as an unchecked supplier. * - * @return unchecked runnable + * @param origin the origin supplier + * @param the type of the result + * @return unchecked supplier + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThSupplier asUnchecked() { - return (ThSupplier) this; + static ThSupplier unchecked(final ThSupplier origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThToDoubleFunction.java b/src/main/java/com/plugatar/jkscope/function/ThToDoubleFunction.java index 1bf7b44..fbcf9ca 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThToDoubleFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThToDoubleFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that produces a {@code double}-valued result and might throw * an exception @@ -36,12 +39,15 @@ public interface ThToDoubleFunction { double apply(T t) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the input argument * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThToDoubleFunction asUnchecked() { - return (ThToDoubleFunction) this; + static ThToDoubleFunction unchecked(final ThToDoubleFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThToIntFunction.java b/src/main/java/com/plugatar/jkscope/function/ThToIntFunction.java index 772eca8..120cc70 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThToIntFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThToIntFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that produces an {@code int}-valued result and might throw an * exception @@ -36,12 +39,15 @@ public interface ThToIntFunction { int apply(T t) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the input argument * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThToIntFunction asUnchecked() { - return (ThToIntFunction) this; + static ThToIntFunction unchecked(final ThToIntFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThToLongFunction.java b/src/main/java/com/plugatar/jkscope/function/ThToLongFunction.java index 65e1c01..22bc10b 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThToLongFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThToLongFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization that produces a {@code long}-valued result and might throw an * exception @@ -36,12 +39,15 @@ public interface ThToLongFunction { long apply(T t) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the input argument * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThToLongFunction asUnchecked() { - return (ThToLongFunction) this; + static ThToLongFunction unchecked(final ThToLongFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThTriConsumer.java b/src/main/java/com/plugatar/jkscope/function/ThTriConsumer.java index 1e6728a..795f87b 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThTriConsumer.java +++ b/src/main/java/com/plugatar/jkscope/function/ThTriConsumer.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Consumer} specialization for 3 input arguments that might throw an exception. * @@ -37,12 +40,17 @@ public interface ThTriConsumer { void accept(T t, U u, V v) throws E; /** - * Returns this consumer as an unchecked consumer. + * Returns given consumer as an unchecked consumer. * + * @param origin the origin consumer + * @param the type of the first input argument + * @param the type of the second input argument + * @param the type of the third input argument * @return unchecked consumer + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThTriConsumer asUnchecked() { - return (ThTriConsumer) this; + static ThTriConsumer unchecked(final ThTriConsumer origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/ThTriFunction.java b/src/main/java/com/plugatar/jkscope/function/ThTriFunction.java index 8b60579..c58d092 100644 --- a/src/main/java/com/plugatar/jkscope/function/ThTriFunction.java +++ b/src/main/java/com/plugatar/jkscope/function/ThTriFunction.java @@ -15,6 +15,9 @@ */ package com.plugatar.jkscope.function; +import static com.plugatar.jkscope.function.Utils.originArgNotNull; +import static com.plugatar.jkscope.function.Utils.uncheckedCast; + /** * The {@link java.util.function.Function} specialization for 3 input arguments that might throw an exception. * @@ -39,12 +42,18 @@ public interface ThTriFunction { R apply(T t, U u, V v) throws E; /** - * Returns this functions as an unchecked functions. + * Returns given function as an unchecked function. * + * @param origin the origin function + * @param the type of the first input argument + * @param the type of the second input argument + * @param the type of the third input argument + * @param the type of the result * @return unchecked function + * @throws NullPointerException if {@code origin} arg is null */ - @SuppressWarnings("unchecked") - default ThTriFunction asUnchecked() { - return (ThTriFunction) this; + static ThTriFunction unchecked(final ThTriFunction origin) { + originArgNotNull(origin); + return uncheckedCast(origin); } } diff --git a/src/main/java/com/plugatar/jkscope/function/Utils.java b/src/main/java/com/plugatar/jkscope/function/Utils.java new file mode 100644 index 0000000..0177259 --- /dev/null +++ b/src/main/java/com/plugatar/jkscope/function/Utils.java @@ -0,0 +1,24 @@ +package com.plugatar.jkscope.function; + +/** + * Utility methods. + */ +final class Utils { + + /** + * Ctor. + */ + private Utils() { + } + + static void originArgNotNull(final Object origin) { + if (origin == null) { + throw new NullPointerException("origin arg is null"); + } + } + + @SuppressWarnings("unchecked") + static T uncheckedCast(final Object obj) { + return (T) obj; + } +} diff --git a/src/test/java/com/plugatar/jkscope/function/ThBiConsumerTest.java b/src/test/java/com/plugatar/jkscope/function/ThBiConsumerTest.java index b4a1cca..8bbeef3 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThBiConsumerTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThBiConsumerTest.java @@ -28,7 +28,15 @@ final class ThBiConsumerTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThBiConsumer origin = null; + + assertThatThrownBy(() -> ThBiConsumer.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value1 = new Object(); final Object value2 = new Object(); final AtomicReference valueRef1 = new AtomicReference<>(); @@ -40,7 +48,7 @@ void asUncheckedMethod() { throw throwable; }; - final ThBiConsumer unchecked = origin.asUnchecked(); + final ThBiConsumer unchecked = ThBiConsumer.unchecked(origin); assertThatThrownBy(() -> unchecked.accept(value1, value2)) .isSameAs(throwable); assertThat(valueRef1.get()) diff --git a/src/test/java/com/plugatar/jkscope/function/ThBiFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThBiFunctionTest.java index 2710c51..e2d9bfe 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThBiFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThBiFunctionTest.java @@ -28,7 +28,15 @@ final class ThBiFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThBiFunction origin = null; + + assertThatThrownBy(() -> ThBiFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value1 = new Object(); final Object value2 = new Object(); final AtomicReference valueRef1 = new AtomicReference<>(); @@ -40,7 +48,7 @@ void asUncheckedMethod() { return result; }; - final ThBiFunction unchecked = origin.asUnchecked(); + final ThBiFunction unchecked = ThBiFunction.unchecked(origin); assertThat(unchecked.apply(value1, value2)) .isSameAs(result); assertThat(valueRef1.get()) @@ -50,13 +58,13 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Object value1 = new Object(); final Object value2 = new Object(); final Throwable throwable = new Throwable(); final ThBiFunction origin = (arg1, arg2) -> { throw throwable; }; - final ThBiFunction unchecked = origin.asUnchecked(); + final ThBiFunction unchecked = ThBiFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value1, value2)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThConsumerTest.java b/src/test/java/com/plugatar/jkscope/function/ThConsumerTest.java index 5153cc9..c82cbe8 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThConsumerTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThConsumerTest.java @@ -28,7 +28,15 @@ final class ThConsumerTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThConsumer origin = null; + + assertThatThrownBy(() -> ThConsumer.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value = new Object(); final AtomicReference valueRef = new AtomicReference<>(); final Throwable throwable = new Throwable(); @@ -37,7 +45,7 @@ void asUncheckedMethod() { throw throwable; }; - final ThConsumer unchecked = origin.asUnchecked(); + final ThConsumer unchecked = ThConsumer.unchecked(origin); assertThatThrownBy(() -> unchecked.accept(value)) .isSameAs(throwable); assertThat(valueRef.get()) diff --git a/src/test/java/com/plugatar/jkscope/function/ThDoubleConsumerTest.java b/src/test/java/com/plugatar/jkscope/function/ThDoubleConsumerTest.java index 70d9b1a..43c8840 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThDoubleConsumerTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThDoubleConsumerTest.java @@ -28,7 +28,15 @@ final class ThDoubleConsumerTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThDoubleConsumer origin = null; + + assertThatThrownBy(() -> ThDoubleConsumer.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final double value = 100.0; final AtomicReference valueRef = new AtomicReference<>(); final Throwable throwable = new Throwable(); @@ -37,7 +45,7 @@ void asUncheckedMethod() { throw throwable; }; - final ThDoubleConsumer unchecked = origin.asUnchecked(); + final ThDoubleConsumer unchecked = ThDoubleConsumer.unchecked(origin); assertThatThrownBy(() -> unchecked.accept(value)) .isSameAs(throwable); assertThat(valueRef.get()) diff --git a/src/test/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunctionTest.java index a5307e8..7ba48f7 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThDoubleObjToDoubleFunctionTest.java @@ -28,7 +28,15 @@ final class ThDoubleObjToDoubleFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThDoubleObjToDoubleFunction origin = null; + + assertThatThrownBy(() -> ThDoubleObjToDoubleFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final double value1 = 100.0; final Object value2 = new Object(); final AtomicReference value1Ref = new AtomicReference(); @@ -40,7 +48,7 @@ void asUncheckedMethod() { return result; }; - final ThDoubleObjToDoubleFunction unchecked = origin.asUnchecked(); + final ThDoubleObjToDoubleFunction unchecked = ThDoubleObjToDoubleFunction.unchecked(origin); assertThat(unchecked.apply(value1, value2)) .isEqualTo(result); assertThat(value1Ref.get()) @@ -50,13 +58,13 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final double value1 = 100.0; final Object value2 = new Object(); final Throwable throwable = new Throwable(); final ThDoubleObjToDoubleFunction origin = (arg1, arg2) -> { throw throwable; }; - final ThDoubleObjToDoubleFunction unchecked = origin.asUnchecked(); + final ThDoubleObjToDoubleFunction unchecked = ThDoubleObjToDoubleFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value1, value2)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThDoubleSupplierTest.java b/src/test/java/com/plugatar/jkscope/function/ThDoubleSupplierTest.java index c83dc4d..7a2d40d 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThDoubleSupplierTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThDoubleSupplierTest.java @@ -26,21 +26,29 @@ final class ThDoubleSupplierTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThDoubleSupplier origin = null; + + assertThatThrownBy(() -> ThDoubleSupplier.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final double result = 100.0; final ThDoubleSupplier origin = () -> result; - final ThDoubleSupplier unchecked = origin.asUnchecked(); + final ThDoubleSupplier unchecked = ThDoubleSupplier.unchecked(origin); assertThat(unchecked.get()) .isEqualTo(result); } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Throwable throwable = new Throwable(); final ThDoubleSupplier origin = () -> { throw throwable; }; - final ThDoubleSupplier unchecked = origin.asUnchecked(); + final ThDoubleSupplier unchecked = ThDoubleSupplier.unchecked(origin); assertThatThrownBy(() -> unchecked.get()) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunctionTest.java index 7d55ecc..2726f39 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThDoubleToDoubleFunctionTest.java @@ -28,7 +28,15 @@ final class ThDoubleToDoubleFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThDoubleToDoubleFunction origin = null; + + assertThatThrownBy(() -> ThDoubleToDoubleFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final double value = 100.0; final AtomicReference valueRef = new AtomicReference<>(); final double result = 999.0; @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThDoubleToDoubleFunction unchecked = origin.asUnchecked(); + final ThDoubleToDoubleFunction unchecked = ThDoubleToDoubleFunction.unchecked(origin); assertThat(unchecked.apply(value)) .isEqualTo(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final double value = 100.0; final Throwable throwable = new Throwable(); final ThDoubleToDoubleFunction origin = arg -> { throw throwable; }; - final ThDoubleToDoubleFunction unchecked = origin.asUnchecked(); + final ThDoubleToDoubleFunction unchecked = ThDoubleToDoubleFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThFunctionTest.java index 10c3c0c..e0c3d59 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThFunctionTest.java @@ -28,7 +28,15 @@ final class ThFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThFunction origin = null; + + assertThatThrownBy(() -> ThFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value = new Object(); final AtomicReference valueRef = new AtomicReference<>(); final Object result = new Object(); @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThFunction unchecked = origin.asUnchecked(); + final ThFunction unchecked = ThFunction.unchecked(origin); assertThat(unchecked.apply(value)) .isSameAs(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Object value = new Object(); final Throwable throwable = new Throwable(); final ThFunction origin = arg -> { throw throwable; }; - final ThFunction unchecked = origin.asUnchecked(); + final ThFunction unchecked = ThFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThIntConsumerTest.java b/src/test/java/com/plugatar/jkscope/function/ThIntConsumerTest.java index 74f0192..2c2e133 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThIntConsumerTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThIntConsumerTest.java @@ -28,7 +28,15 @@ final class ThIntConsumerTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThIntConsumer origin = null; + + assertThatThrownBy(() -> ThIntConsumer.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final int value = 100; final AtomicInteger valueRef = new AtomicInteger(); final Throwable throwable = new Throwable(); @@ -37,7 +45,7 @@ void asUncheckedMethod() { throw throwable; }; - final ThIntConsumer unchecked = origin.asUnchecked(); + final ThIntConsumer unchecked = ThIntConsumer.unchecked(origin); assertThatThrownBy(() -> unchecked.accept(value)) .isSameAs(throwable); assertThat(valueRef.get()) diff --git a/src/test/java/com/plugatar/jkscope/function/ThIntObjToIntFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThIntObjToIntFunctionTest.java index cec21fa..31b00fb 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThIntObjToIntFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThIntObjToIntFunctionTest.java @@ -29,7 +29,15 @@ final class ThIntObjToIntFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThIntObjToIntFunction origin = null; + + assertThatThrownBy(() -> ThIntObjToIntFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final int value1 = 100; final Object value2 = new Object(); final AtomicInteger value1Ref = new AtomicInteger(); @@ -41,7 +49,7 @@ void asUncheckedMethod() { return result; }; - final ThIntObjToIntFunction unchecked = origin.asUnchecked(); + final ThIntObjToIntFunction unchecked = ThIntObjToIntFunction.unchecked(origin); assertThat(unchecked.apply(value1, value2)) .isEqualTo(result); assertThat(value1Ref.get()) @@ -51,13 +59,13 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final int value1 = 100; final Object value2 = new Object(); final Throwable throwable = new Throwable(); final ThIntObjToIntFunction origin = (arg1, arg2) -> { throw throwable; }; - final ThIntObjToIntFunction unchecked = origin.asUnchecked(); + final ThIntObjToIntFunction unchecked = ThIntObjToIntFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value1, value2)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThIntSupplierTest.java b/src/test/java/com/plugatar/jkscope/function/ThIntSupplierTest.java index 677528e..954ab73 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThIntSupplierTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThIntSupplierTest.java @@ -26,21 +26,29 @@ final class ThIntSupplierTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThIntSupplier origin = null; + + assertThatThrownBy(() -> ThIntSupplier.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final int result = 100; final ThIntSupplier origin = () -> result; - final ThIntSupplier unchecked = origin.asUnchecked(); + final ThIntSupplier unchecked = ThIntSupplier.unchecked(origin); assertThat(unchecked.get()) .isEqualTo(result); } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Throwable throwable = new Throwable(); final ThIntSupplier origin = () -> { throw throwable; }; - final ThIntSupplier unchecked = origin.asUnchecked(); + final ThIntSupplier unchecked = ThIntSupplier.unchecked(origin); assertThatThrownBy(() -> unchecked.get()) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThIntToIntFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThIntToIntFunctionTest.java index a764966..53a305f 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThIntToIntFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThIntToIntFunctionTest.java @@ -28,7 +28,15 @@ final class ThIntToIntFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThIntToIntFunction origin = null; + + assertThatThrownBy(() -> ThIntToIntFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final int value = 100; final AtomicInteger valueRef = new AtomicInteger(); final int result = 999; @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThIntToIntFunction unchecked = origin.asUnchecked(); + final ThIntToIntFunction unchecked = ThIntToIntFunction.unchecked(origin); assertThat(unchecked.apply(value)) .isEqualTo(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final int value = 100; final Throwable throwable = new Throwable(); final ThIntToIntFunction origin = arg -> { throw throwable; }; - final ThIntToIntFunction unchecked = origin.asUnchecked(); + final ThIntToIntFunction unchecked = ThIntToIntFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThLongConsumerTest.java b/src/test/java/com/plugatar/jkscope/function/ThLongConsumerTest.java index 17e99e7..c3b76ca 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThLongConsumerTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThLongConsumerTest.java @@ -28,7 +28,15 @@ final class ThLongConsumerTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThLongConsumer origin = null; + + assertThatThrownBy(() -> ThLongConsumer.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final long value = 100L; final AtomicLong valueRef = new AtomicLong(); final Throwable throwable = new Throwable(); @@ -37,7 +45,7 @@ void asUncheckedMethod() { throw throwable; }; - final ThLongConsumer unchecked = origin.asUnchecked(); + final ThLongConsumer unchecked = ThLongConsumer.unchecked(origin); assertThatThrownBy(() -> unchecked.accept(value)) .isSameAs(throwable); assertThat(valueRef.get()) diff --git a/src/test/java/com/plugatar/jkscope/function/ThLongObjToLongFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThLongObjToLongFunctionTest.java index 8ffafb7..91bd9fd 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThLongObjToLongFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThLongObjToLongFunctionTest.java @@ -29,7 +29,15 @@ final class ThLongObjToLongFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThLongObjToLongFunction origin = null; + + assertThatThrownBy(() -> ThLongObjToLongFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final long value1 = 100L; final Object value2 = new Object(); final AtomicLong value1Ref = new AtomicLong(); @@ -41,7 +49,7 @@ void asUncheckedMethod() { return result; }; - final ThLongObjToLongFunction unchecked = origin.asUnchecked(); + final ThLongObjToLongFunction unchecked = ThLongObjToLongFunction.unchecked(origin); assertThat(unchecked.apply(value1, value2)) .isEqualTo(result); assertThat(value1Ref.get()) @@ -51,13 +59,13 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final long value1 = 100L; final Object value2 = new Object(); final Throwable throwable = new Throwable(); final ThLongObjToLongFunction origin = (arg1, arg2) -> { throw throwable; }; - final ThLongObjToLongFunction unchecked = origin.asUnchecked(); + final ThLongObjToLongFunction unchecked = ThLongObjToLongFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value1, value2)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThLongSupplierTest.java b/src/test/java/com/plugatar/jkscope/function/ThLongSupplierTest.java index 2e6a1ae..6292a8d 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThLongSupplierTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThLongSupplierTest.java @@ -26,21 +26,29 @@ final class ThLongSupplierTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThLongSupplier origin = null; + + assertThatThrownBy(() -> ThLongSupplier.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final long result = 100L; final ThLongSupplier origin = () -> result; - final ThLongSupplier unchecked = origin.asUnchecked(); + final ThLongSupplier unchecked = ThLongSupplier.unchecked(origin); assertThat(unchecked.get()) .isEqualTo(result); } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Throwable throwable = new Throwable(); final ThLongSupplier origin = () -> { throw throwable; }; - final ThLongSupplier unchecked = origin.asUnchecked(); + final ThLongSupplier unchecked = ThLongSupplier.unchecked(origin); assertThatThrownBy(() -> unchecked.get()) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThLongToLongFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThLongToLongFunctionTest.java index 46d0c09..21907f0 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThLongToLongFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThLongToLongFunctionTest.java @@ -28,7 +28,15 @@ final class ThLongToLongFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThLongToLongFunction origin = null; + + assertThatThrownBy(() -> ThLongToLongFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final long value = 100; final AtomicLong valueRef = new AtomicLong(); final long result = 999; @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThLongToLongFunction unchecked = origin.asUnchecked(); + final ThLongToLongFunction unchecked = ThLongToLongFunction.unchecked(origin); assertThat(unchecked.apply(value)) .isEqualTo(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final long value = 100; final Throwable throwable = new Throwable(); final ThLongToLongFunction origin = arg -> { throw throwable; }; - final ThLongToLongFunction unchecked = origin.asUnchecked(); + final ThLongToLongFunction unchecked = ThLongToLongFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThPredicateTest.java b/src/test/java/com/plugatar/jkscope/function/ThPredicateTest.java index 4b45d86..7300547 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThPredicateTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThPredicateTest.java @@ -28,7 +28,15 @@ final class ThPredicateTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThPredicate origin = null; + + assertThatThrownBy(() -> ThPredicate.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value = new Object(); final AtomicReference valueRef = new AtomicReference<>(); final boolean result = true; @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThPredicate unchecked = origin.asUnchecked(); + final ThPredicate unchecked = ThPredicate.unchecked(origin); assertThat(unchecked.test(value)) .isSameAs(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Object value = new Object(); final Throwable throwable = new Throwable(); final ThPredicate origin = arg -> { throw throwable; }; - final ThPredicate unchecked = origin.asUnchecked(); + final ThPredicate unchecked = ThPredicate.unchecked(origin); assertThatThrownBy(() -> unchecked.test(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThRunnableTest.java b/src/test/java/com/plugatar/jkscope/function/ThRunnableTest.java index 075d43b..20f3752 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThRunnableTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThRunnableTest.java @@ -28,7 +28,15 @@ final class ThRunnableTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThRunnable origin = null; + + assertThatThrownBy(() -> ThRunnable.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final AtomicBoolean sideEffect = new AtomicBoolean(false); final Throwable throwable = new Throwable(); final ThRunnable origin = () -> { @@ -36,7 +44,7 @@ void asUncheckedMethod() { throw throwable; }; - final ThRunnable unchecked = origin.asUnchecked(); + final ThRunnable unchecked = ThRunnable.unchecked(origin); assertThatThrownBy(() -> unchecked.run()) .isSameAs(throwable); assertThat(sideEffect.get()) diff --git a/src/test/java/com/plugatar/jkscope/function/ThSupplierTest.java b/src/test/java/com/plugatar/jkscope/function/ThSupplierTest.java index 7f5c953..cfd141f 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThSupplierTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThSupplierTest.java @@ -26,21 +26,29 @@ final class ThSupplierTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThSupplier origin = null; + + assertThatThrownBy(() -> ThSupplier.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object result = new Object(); final ThSupplier origin = () -> result; - final ThSupplier unchecked = origin.asUnchecked(); + final ThSupplier unchecked = ThSupplier.unchecked(origin); assertThat(unchecked.get()) .isSameAs(result); } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Throwable throwable = new Throwable(); final ThSupplier origin = () -> { throw throwable; }; - final ThSupplier unchecked = origin.asUnchecked(); + final ThSupplier unchecked = ThSupplier.unchecked(origin); assertThatThrownBy(() -> unchecked.get()) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThToDoubleFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThToDoubleFunctionTest.java index 8681fda..d5e8800 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThToDoubleFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThToDoubleFunctionTest.java @@ -28,7 +28,15 @@ final class ThToDoubleFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThToDoubleFunction origin = null; + + assertThatThrownBy(() -> ThToDoubleFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value = new Object(); final AtomicReference valueRef = new AtomicReference<>(); final double result = 111.0; @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThToDoubleFunction unchecked = origin.asUnchecked(); + final ThToDoubleFunction unchecked = ThToDoubleFunction.unchecked(origin); assertThat(unchecked.apply(value)) .isEqualTo(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Object value = new Object(); final Throwable throwable = new Throwable(); final ThToDoubleFunction origin = arg -> { throw throwable; }; - final ThToDoubleFunction unchecked = origin.asUnchecked(); + final ThToDoubleFunction unchecked = ThToDoubleFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThToIntFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThToIntFunctionTest.java index 03566a9..2f25c45 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThToIntFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThToIntFunctionTest.java @@ -28,7 +28,15 @@ final class ThToIntFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThToIntFunction origin = null; + + assertThatThrownBy(() -> ThToIntFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value = new Object(); final AtomicReference valueRef = new AtomicReference<>(); final int result = 111; @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThToIntFunction unchecked = origin.asUnchecked(); + final ThToIntFunction unchecked = ThToIntFunction.unchecked(origin); assertThat(unchecked.apply(value)) .isEqualTo(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Object value = new Object(); final Throwable throwable = new Throwable(); final ThToIntFunction origin = arg -> { throw throwable; }; - final ThToIntFunction unchecked = origin.asUnchecked(); + final ThToIntFunction unchecked = ThToIntFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThToLongFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThToLongFunctionTest.java index 2eb6770..66e02c9 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThToLongFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThToLongFunctionTest.java @@ -28,7 +28,15 @@ final class ThToLongFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThToLongFunction origin = null; + + assertThatThrownBy(() -> ThToLongFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value = new Object(); final AtomicReference valueRef = new AtomicReference<>(); final long result = 111L; @@ -37,7 +45,7 @@ void asUncheckedMethod() { return result; }; - final ThToLongFunction unchecked = origin.asUnchecked(); + final ThToLongFunction unchecked = ThToLongFunction.unchecked(origin); assertThat(unchecked.apply(value)) .isEqualTo(result); assertThat(valueRef.get()) @@ -45,12 +53,12 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Object value = new Object(); final Throwable throwable = new Throwable(); final ThToLongFunction origin = arg -> { throw throwable; }; - final ThToLongFunction unchecked = origin.asUnchecked(); + final ThToLongFunction unchecked = ThToLongFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value)) .isSameAs(throwable); } diff --git a/src/test/java/com/plugatar/jkscope/function/ThTriConsumerTest.java b/src/test/java/com/plugatar/jkscope/function/ThTriConsumerTest.java index 52f5ba3..f4e53ca 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThTriConsumerTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThTriConsumerTest.java @@ -28,7 +28,15 @@ final class ThTriConsumerTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThTriConsumer origin = null; + + assertThatThrownBy(() -> ThTriConsumer.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value1 = new Object(); final Object value2 = new Object(); final Object value3 = new Object(); @@ -43,7 +51,7 @@ void asUncheckedMethod() { throw throwable; }; - final ThTriConsumer unchecked = origin.asUnchecked(); + final ThTriConsumer unchecked = ThTriConsumer.unchecked(origin); assertThatThrownBy(() -> unchecked.accept(value1, value2, value3)) .isSameAs(throwable); assertThat(valueRef1.get()) diff --git a/src/test/java/com/plugatar/jkscope/function/ThTriFunctionTest.java b/src/test/java/com/plugatar/jkscope/function/ThTriFunctionTest.java index 24197e2..4ea6eb2 100644 --- a/src/test/java/com/plugatar/jkscope/function/ThTriFunctionTest.java +++ b/src/test/java/com/plugatar/jkscope/function/ThTriFunctionTest.java @@ -28,7 +28,15 @@ final class ThTriFunctionTest { @Test - void asUncheckedMethod() { + void uncheckedStaticMethodThrowsNPEForNullArg() { + final ThTriFunction origin = null; + + assertThatThrownBy(() -> ThTriFunction.unchecked(origin)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void uncheckedStaticMethod() { final Object value1 = new Object(); final Object value2 = new Object(); final Object value3 = new Object(); @@ -43,7 +51,7 @@ void asUncheckedMethod() { return functionResult; }; - final ThTriFunction unchecked = origin.asUnchecked(); + final ThTriFunction unchecked = ThTriFunction.unchecked(origin); assertThat(unchecked.apply(value1, value2, value3)) .isSameAs(functionResult); assertThat(valueRef1.get()) @@ -55,7 +63,7 @@ void asUncheckedMethod() { } @Test - void asUncheckedMethodThrowsException() { + void uncheckedStaticMethodThrowsException() { final Object value1 = new Object(); final Object value2 = new Object(); final Object value3 = new Object(); @@ -64,7 +72,7 @@ void asUncheckedMethodThrowsException() { throw throwable; }; - final ThTriFunction unchecked = origin.asUnchecked(); + final ThTriFunction unchecked = ThTriFunction.unchecked(origin); assertThatThrownBy(() -> unchecked.apply(value1, value2, value3)) .isSameAs(throwable); }