From d4329e74262c7f45926347e97878916603c6c348 Mon Sep 17 00:00:00 2001 From: Jose Luis Leon Date: Sat, 3 Feb 2024 04:01:58 -0500 Subject: [PATCH] perf(core): Remove deprecated API (#228) BREAKING CHANGE: Deprecated API has been removed in favor of the new API --- .../joselion/maybe/CloseableHandler.java | 49 ----- .../github/joselion/maybe/EffectHandler.java | 37 ---- .../java/io/github/joselion/maybe/Maybe.java | 200 ------------------ .../github/joselion/maybe/SolveHandler.java | 81 ------- .../io/github/joselion/maybe/Maybe.java | 200 ------------------ .../joselion/maybe/CloseableHandlerTests.java | 21 -- .../joselion/maybe/EffectHandlerTests.java | 14 -- .../io/github/joselion/maybe/MaybeTests.java | 102 --------- .../joselion/maybe/SolveHandlerTests.java | 26 --- 9 files changed, 730 deletions(-) diff --git a/src/main/java/io/github/joselion/maybe/CloseableHandler.java b/src/main/java/io/github/joselion/maybe/CloseableHandler.java index 1fc94f2..45ae829 100644 --- a/src/main/java/io/github/joselion/maybe/CloseableHandler.java +++ b/src/main/java/io/github/joselion/maybe/CloseableHandler.java @@ -115,31 +115,6 @@ public SolveHandler solve( ); } - /** - * If the resource is present, solves the value of a throwing operation - * using a {@link ThrowingFunction} expression which has the previously - * prepared resource in the argument. The resource is automatically closed - * after the operation finishes, just like a common try-with-resources - * statement. - *

- * Returs a {@link SolveHandler} which allows to handle the possible error - * and return a safe value. The returned handler is {@code empty} if neither - * the resource nor the error is present. - * - * @param the type of the value returned by the {@code solver} - * @param the type of exception the {@code solver} may throw - * @param solver the checked function operation to solve - * @return a {@link SolveHandler} with either the value solved or the thrown - * exception to be handled - * @deprecated in favor of {@link #solve(ThrowingFunction)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public SolveHandler resolveClosing(// NOSONAR - final ThrowingFunction solver - ) { - return this.solve(solver); - } - /** * If the resource is present, runs an effect that may throw an exception * using a {@link ThrowingConsumer} expression which has the previously @@ -174,28 +149,4 @@ public EffectHandler effect( } ); } - - /** - * If the resource is present, runs an effect that may throw an exception - * using a {@link ThrowingConsumer} expression which has the previously - * prepared resource in the argument. The resource is automatically closed - * after the operation finishes, just like a common try-with-resources - * statement. - *

- * Returning then an {@link EffectHandler} which allows to handle the - * possible error. The returned handler is {@code empty} if neither the - * resource nor the error is present. - * - * @param the type of exception the {@code effect} may throw - * @param effect the checked consumer operation to execute - * @return an {@link EffectHandler} with either the thrown exception to be - * handled or empty - * @deprecated in favor of {@link #effect(ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public EffectHandler runEffectClosing(// NOSONAR - final ThrowingConsumer effect - ) { - return this.effect(effect); - } } diff --git a/src/main/java/io/github/joselion/maybe/EffectHandler.java b/src/main/java/io/github/joselion/maybe/EffectHandler.java index 3dd2a27..010a88e 100644 --- a/src/main/java/io/github/joselion/maybe/EffectHandler.java +++ b/src/main/java/io/github/joselion/maybe/EffectHandler.java @@ -172,25 +172,6 @@ public EffectHandler effect( .orElseGet(() -> Maybe.from(onSuccess)); } - /** - * Chain another effect covering both cases of success or error of the - * previous effect in two different callbacks. - * - * @param the type of the error the new effect may throw - * @param onSuccess a runnable checked function to run in case of succeess - * @param onError a runnable checked function to run in case of error - * @return a new {@link EffectHandler} representing the result of one of the - * invoked callback - * @deprecated in favor of {@link #effect(ThrowingRunnable, ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public EffectHandler runEffect(// NOSONAR - final ThrowingRunnable onSuccess, - final ThrowingConsumer onError - ) { - return this.effect(onSuccess, onError); - } - /** * Chain another effect if the previous completed with no error. Otherwise, * ignores the current error and return a new {@link EffectHandler} that is @@ -205,24 +186,6 @@ public EffectHandler effect(final ThrowingRunnable { }); } - /** - * Chain another effect if the previous completed with no error. Otherwise, - * ignores the current error and return a new {@link EffectHandler} that is - * either empty or has a different error cause by the next effect. - * - * @param the type of the error the new effect may throw - * @param effect a runnable checked function to run in case of succeess - * @return a new {@link EffectHandler} that is either empty or with the - * thrown error - * @deprecated in favor of {@link #effect(ThrowingRunnable)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public EffectHandler runEffect(// NOSONAR - final ThrowingRunnable effect - ) { - return this.effect(effect); - } - /** * Terminal operation to handle the error if present. The error is passed in * the argument of the {@code effect} consumer. diff --git a/src/main/java/io/github/joselion/maybe/Maybe.java b/src/main/java/io/github/joselion/maybe/Maybe.java index b354079..bdae4b1 100644 --- a/src/main/java/io/github/joselion/maybe/Maybe.java +++ b/src/main/java/io/github/joselion/maybe/Maybe.java @@ -83,21 +83,6 @@ public static Maybe of(final @Nullable Optional value) { // NOSONAR return new Maybe<>(null); } - /** - * Creates a {@link Maybe} wrapper of the given value. If the value is - * {@code null}, it returns a {@link #empty()}. - * - * @param the type of the value - * @param value the value be wrapped - * @return a {@code Maybe} wrapping the value if it's non-{@code null}, - * {@link #empty()} otherwise - * @deprecated in favor of {@link #of(Object)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Maybe just(final @Nullable T value) { // NOSONAR - return Maybe.of(value); - } - /** * Creates an empty {@link Maybe} instance. * @@ -108,40 +93,6 @@ public static Maybe empty() { return Maybe.of(null); } - /** - * Creates an empty {@link Maybe} instance. - * - * @param the type of the value - * @return an empty {@code Maybe} - * @deprecated in favor of {@link #empty()} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Maybe nothing() { // NOSONAR - return Maybe.empty(); - } - - /** - * Creates a {@link Maybe} wrapper of the given value if the optional is not - * empty. Returns a {@link #empty()} otherwise. - *

- * This is a convenience creator that would be equivalent to: - *

-   *  Maybe.of(opt)
-   *    .solve(Optional::get)
-   *    .toMaybe();
-   * 
- * - * @param the type of the value - * @param value an optional value to create the wrapper from - * @return a {@code Maybe} wrapping the value if it's not empty. - * {@link #empty()} otherwise - * @deprecated in favor of {@link #of(Optional)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Maybe fromOptional(final Optional value) { // NOSONAR - return Maybe.of(value); - } - /** * Solves the value of a throwing operation using a {@link ThrowingSupplier} * expression. Returning then a {@link SolveHandler} which allows to handle @@ -164,25 +115,6 @@ public static SolveHandler from( } } - /** - * Solves the value of a throwing operation using a {@link ThrowingSupplier} - * expression. Returning then a {@link SolveHandler} which allows to handle - * the possible error and return a safe value. - * - * @param the type of the value returned by the {@code solver} - * @param the type of exception the {@code solver} may throw - * @param solver the checked supplier operation to solve - * @return a {@link SolveHandler} with either the value solved or the thrown - * exception to be handled - * @deprecated in favor of {@link #from(ThrowingSupplier)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static SolveHandler fromResolver(// NOSONAR - final ThrowingSupplier solver - ) { - return Maybe.from(solver); - } - /** * Runs an effect that may throw an exception using a {@link ThrowingRunnable} * expression. Returning then an {@link EffectHandler} which allows to handle @@ -203,24 +135,6 @@ public static EffectHandler from(final ThrowingRunnable } } - /** - * Runs an effect that may throw an exception using a {@link ThrowingRunnable} - * expression. Returning then an {@link EffectHandler} which allows to handle - * the possible error. - * - * @param the type of exception the {@code effect} may throw - * @param effect the checked runnable operation to execute - * @return an {@link EffectHandler} with either the thrown exception to be - * handled or empty - * @deprecated in favor of {@link #from(ThrowingRunnable)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static EffectHandler fromEffect(// NOSONAR - final ThrowingRunnable effect - ) { - return Maybe.from(effect); - } - /** * Convenience partial application of a {@code solver}. This method creates * a function that receives an {@code S} value which can be used to produce a @@ -253,40 +167,6 @@ public static Function> partia return value -> Maybe.from(() -> solver.apply(value)); } - /** - * Convenience partial application of a {@code solver}. This method creates - * a function that receives an {@code S} value which can be used to produce a - * {@link SolveHandler} once applied. This is specially useful when we want - * to create a {@link Maybe} from a callback argument, like on a - * {@link Optional#map(Function)} for instance. - *

- * In other words, the following code - *

-   *  Optional.of(value)
-   *    .map(str -> Maybe.from(() -> decode(str)));
-   * 
- * Is equivalent to - *
-   *  Optional.of(value)
-   *    .map(Maybe.partialResolver(this::decode));
-   * 
- * - * @param the type of the value the returned function receives - * @param the type of the value to be solved - * @param the type of the error the solver may throw - * @param solver a checked function that receives an {@code S} value and - * returns a {@code T} value - * @return a partially applied {@link SolveHandler}. This means, a function - * that receives an {@code S} value, and produces a {@code SolveHandler} - * @deprecated in favor of {@link #partial(ThrowingFunction)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Function> partialResolver(// NOSONAR - final ThrowingFunction solver - ) { - return Maybe.partial(solver); - } - /** * Convenience partial application of an {@code effect}. This method creates * a function that receives an {@code S} value which can be used to produce @@ -317,38 +197,6 @@ public static Function> partial( return value -> Maybe.from(() -> effect.accept(value)); } - /** - * Convenience partial application of an {@code effect}. This method creates - * a function that receives an {@code S} value which can be used to produce - * an {@link EffectHandler} once applied. This is specially useful when we - * want to create a {@link Maybe} from a callback argument, like on a - * {@link Optional#map(Function)} for instance. - *

- * In other words, the following code - *

-   *  Optional.of(value)
-   *    .map(msg -> Maybe.from(() -> sendMessage(msg)));
-   * 
- * Is equivalent to - *
-   *  Optional.of(value)
-   *    .map(Maybe.partialEffect(this::sendMessage));
-   * 
- * - * @param the type of the value the returned function receives - * @param the type of the error the effect may throw - * @param effect a checked consumer that receives an {@code S} value - * @return a partially applied {@link EffectHandler}. This means, a function - * that receives an {@code S} value, and produces an {@code EffectHandler} - * @deprecated in favor of {@link #partial(ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Function> partialEffect(// NOSONAR - final ThrowingConsumer effect - ) { - return Maybe.partial(effect); - } - /** * Prepare an {@link AutoCloseable} resource to use in a solver or effect. * The resource will be automatically closed after the operation is finished, @@ -447,26 +295,6 @@ public SolveHandler solve( } } - /** - * Chain the {@code Maybe} with another solver, if and only if the previous - * operation was handled with no errors. The value of the previous operation - * is passed as argument of the {@link ThrowingFunction}. - * - * @param the type of value returned by the next operation - * @param the type of exception the new solver may throw - * @param solver a checked function that receives the current value and - * solves another - * @return a {@link SolveHandler} with either the solved value, or the - * thrown exception to be handled - * @deprecated in favor of {@link #solve(ThrowingFunction)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public SolveHandler resolve(// NOSONAR - final ThrowingFunction solver - ) { - return this.solve(solver); - } - /** * Chain the {@code Maybe} with another effect, if and only if the previous * operation was handled with no errors. @@ -487,23 +315,6 @@ public EffectHandler effect(final ThrowingConsumer the type of exception the new effect may throw - * @param effect the checked runnable operation to execute next - * @return an {@link EffectHandler} with either the thrown exception to be - * handled or nothing - * @deprecated in favor of {@link #effect(ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public EffectHandler runEffect(// NOSONAR - final ThrowingConsumer effect - ) { - return this.effect(effect); - } - /** * If the value is present, cast the value to another type. In case of an * exception during the cast, a Maybe with {@link #empty()} is returned. @@ -537,17 +348,6 @@ public boolean isEmpty() { return this.value.isEmpty(); } - /** - * Checks if the {@code Maybe} is empty. That is, when no value is present. - * - * @return true if the value is not present, false otherwise - * @deprecated in favor of {@link #isEmpty()} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public boolean hasNothing() { // NOSONAR - return this.isEmpty(); - } - /** * Safely unbox the value as an {@link Optional} which may or may not contain * a value. diff --git a/src/main/java/io/github/joselion/maybe/SolveHandler.java b/src/main/java/io/github/joselion/maybe/SolveHandler.java index 18d100d..62743dc 100644 --- a/src/main/java/io/github/joselion/maybe/SolveHandler.java +++ b/src/main/java/io/github/joselion/maybe/SolveHandler.java @@ -199,32 +199,6 @@ public SolveHandler solve( ); } - /** - * Chain another solver covering both cases of success or error of the - * previous solver in two different callbacks. - *

- * The first callback receives the solved value, the second callback the - * caught error. Both should solve another value of the same type {@code S}, - * but only one of the callbacks is invoked. It depends on whether the - * previous value was solved or not. - * - * @param the type of value returned by the next operation - * @param the type of exception the new solver may throw - * @param onSuccess a checked function that receives the current value - * and solves another - * @param onError a checked function that receives the error and - * solves another value - * @return a new handler with either the solved value or the error - * @deprecated in favor of {@link #solve(ThrowingFunction, ThrowingFunction)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public SolveHandler resolve(// NOSONAR - final ThrowingFunction onSuccess, - final ThrowingFunction onError - ) { - return this.solve(onSuccess, onError); - } - /** * Chain another solver function if the value was solved. Otherwise, * returns a handler containing the error so it can be propagated upstream. @@ -246,24 +220,6 @@ public SolveHandler solve( ); } - /** - * Chain another solver function if the value was solved. Otherwise, - * returns a handler containing the error so it can be propagated upstream. - * - * @param the type of value returned by the next operation - * @param the type of exception the new solver may throw - * @param solver a checked function that receives the current value and - * solves another - * @return a new handler with either the solved value or an error - * @deprecated in favor of {@link #solve(ThrowingFunction)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public SolveHandler resolve(// NOSONAR - final ThrowingFunction solver - ) { - return this.solve(solver); - } - /** * Chain the previous operation to an effect covering both the success or * error cases in two different callbacks. @@ -284,25 +240,6 @@ public EffectHandler effect( ); } - /** - * Chain the previous operation to an effect covering both the success or - * error cases in two different callbacks. - * - * @param the type of the error the effect may throw - * @param onSuccess a consumer checked function to run in case of succeess - * @param onError a consumer checked function to run in case of error - * @return an {@link EffectHandler} representing the result of one of the - * invoked callback - * @deprecated in favor of {@link #effect(ThrowingConsumer, ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public EffectHandler runEffect(// NOSONAR - final ThrowingConsumer onSuccess, - final ThrowingConsumer onError - ) { - return this.effect(onSuccess, onError); - } - /** * Chain the previous operation to an effect if the value was solved. * Otherwise, returns a handler containing the error so it can be propagated @@ -322,24 +259,6 @@ public EffectHandler effect(final ThrowingConsumer the type of the error the effect may throw - * @param effect a consume checked function to run in case of succeess - * @return a new {@link EffectHandler} representing the result of the success - * callback or containg the error - * @deprecated in favor of {@link #effect(ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public EffectHandler runEffect(// NOSONAR - final ThrowingConsumer effect - ) { - return this.effect(effect); - } - /** * If the value is present, map it to another value using the {@code mapper} * function. If an error is present, the {@code mapper} function is never diff --git a/src/main/java17/io/github/joselion/maybe/Maybe.java b/src/main/java17/io/github/joselion/maybe/Maybe.java index 0d08d88..63b5d55 100644 --- a/src/main/java17/io/github/joselion/maybe/Maybe.java +++ b/src/main/java17/io/github/joselion/maybe/Maybe.java @@ -83,21 +83,6 @@ public static Maybe of(final @Nullable Optional value) { // NOSONAR return new Maybe<>(null); } - /** - * Creates a {@link Maybe} wrapper of the given value. If the value is - * {@code null}, it returns a {@link #empty()}. - * - * @param the type of the value - * @param value the value be wrapped - * @return a {@code Maybe} wrapping the value if it's non-{@code null}, - * {@link #empty()} otherwise - * @deprecated in favor of {@link #of(Object)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Maybe just(final @Nullable T value) { // NOSONAR - return Maybe.of(value); - } - /** * Creates an empty {@link Maybe} instance. * @@ -108,40 +93,6 @@ public static Maybe empty() { return Maybe.of(null); } - /** - * Creates an empty {@link Maybe} instance. - * - * @param the type of the value - * @return an empty {@code Maybe} - * @deprecated in favor of {@link #empty()} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Maybe nothing() { // NOSONAR - return Maybe.empty(); - } - - /** - * Creates a {@link Maybe} wrapper of the given value if the optional is not - * empty. Returns a {@link #empty()} otherwise. - *

- * This is a convenience creator that would be equivalent to: - *

-   *  Maybe.of(opt)
-   *    .solve(Optional::get)
-   *    .toMaybe();
-   * 
- * - * @param the type of the value - * @param value an optional value to create the wrapper from - * @return a {@code Maybe} wrapping the value if it's not empty. - * {@link #empty()} otherwise - * @deprecated in favor of {@link #of(Optional)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Maybe fromOptional(final Optional value) { // NOSONAR - return Maybe.of(value); - } - /** * Solves the value of a throwing operation using a {@link ThrowingSupplier} * expression. Returning then a {@link SolveHandler} which allows to handle @@ -164,25 +115,6 @@ public static SolveHandler from( } } - /** - * Solves the value of a throwing operation using a {@link ThrowingSupplier} - * expression. Returning then a {@link SolveHandler} which allows to handle - * the possible error and return a safe value. - * - * @param the type of the value returned by the {@code solver} - * @param the type of exception the {@code solver} may throw - * @param solver the checked supplier operation to solve - * @return a {@link SolveHandler} with either the value solved or the thrown - * exception to be handled - * @deprecated in favor of {@link #from(ThrowingSupplier)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static SolveHandler fromResolver(// NOSONAR - final ThrowingSupplier solver - ) { - return Maybe.from(solver); - } - /** * Runs an effect that may throw an exception using a {@link ThrowingRunnable} * expression. Returning then an {@link EffectHandler} which allows to handle @@ -203,24 +135,6 @@ public static EffectHandler from(final ThrowingRunnable } } - /** - * Runs an effect that may throw an exception using a {@link ThrowingRunnable} - * expression. Returning then an {@link EffectHandler} which allows to handle - * the possible error. - * - * @param the type of exception the {@code effect} may throw - * @param effect the checked runnable operation to execute - * @return an {@link EffectHandler} with either the thrown exception to be - * handled or empty - * @deprecated in favor of {@link #from(ThrowingRunnable)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static EffectHandler fromEffect(// NOSONAR - final ThrowingRunnable effect - ) { - return Maybe.from(effect); - } - /** * Convenience partial application of a {@code solver}. This method creates * a function that receives an {@code S} value which can be used to produce a @@ -253,40 +167,6 @@ public static Function> partia return value -> Maybe.from(() -> solver.apply(value)); } - /** - * Convenience partial application of a {@code solver}. This method creates - * a function that receives an {@code S} value which can be used to produce a - * {@link SolveHandler} once applied. This is specially useful when we want - * to create a {@link Maybe} from a callback argument, like on a - * {@link Optional#map(Function)} for instance. - *

- * In other words, the following code - *

-   *  Optional.of(value)
-   *    .map(str -> Maybe.from(() -> decode(str)));
-   * 
- * Is equivalent to - *
-   *  Optional.of(value)
-   *    .map(Maybe.partialResolver(this::decode));
-   * 
- * - * @param the type of the value the returned function receives - * @param the type of the value to be solved - * @param the type of the error the solver may throw - * @param solver a checked function that receives an {@code S} value and - * returns a {@code T} value - * @return a partially applied {@link SolveHandler}. This means, a function - * that receives an {@code S} value, and produces a {@code SolveHandler} - * @deprecated in favor of {@link #partial(ThrowingFunction)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Function> partialResolver(// NOSONAR - final ThrowingFunction solver - ) { - return Maybe.partial(solver); - } - /** * Convenience partial application of an {@code effect}. This method creates * a function that receives an {@code S} value which can be used to produce @@ -317,38 +197,6 @@ public static Function> partial( return value -> Maybe.from(() -> effect.accept(value)); } - /** - * Convenience partial application of an {@code effect}. This method creates - * a function that receives an {@code S} value which can be used to produce - * an {@link EffectHandler} once applied. This is specially useful when we - * want to create a {@link Maybe} from a callback argument, like on a - * {@link Optional#map(Function)} for instance. - *

- * In other words, the following code - *

-   *  Optional.of(value)
-   *    .map(msg -> Maybe.from(() -> sendMessage(msg)));
-   * 
- * Is equivalent to - *
-   *  Optional.of(value)
-   *    .map(Maybe.partialEffect(this::sendMessage));
-   * 
- * - * @param the type of the value the returned function receives - * @param the type of the error the effect may throw - * @param effect a checked consumer that receives an {@code S} value - * @return a partially applied {@link EffectHandler}. This means, a function - * that receives an {@code S} value, and produces an {@code EffectHandler} - * @deprecated in favor of {@link #partial(ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public static Function> partialEffect(// NOSONAR - final ThrowingConsumer effect - ) { - return Maybe.partial(effect); - } - /** * Prepare an {@link AutoCloseable} resource to use in a solver or effect. * The resource will be automatically closed after the operation is finished, @@ -447,26 +295,6 @@ public SolveHandler solve( } } - /** - * Chain the {@code Maybe} with another solver, if and only if the previous - * operation was handled with no errors. The value of the previous operation - * is passed as argument of the {@link ThrowingFunction}. - * - * @param the type of value returned by the next operation - * @param the type of exception the new solver may throw - * @param solver a checked function that receives the current value and - * solves another - * @return a {@link SolveHandler} with either the solved value, or the - * thrown exception to be handled - * @deprecated in favor of {@link #solve(ThrowingFunction)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public SolveHandler resolve(// NOSONAR - final ThrowingFunction solver - ) { - return this.solve(solver); - } - /** * Chain the {@code Maybe} with another effect, if and only if the previous * operation was handled with no errors. @@ -487,23 +315,6 @@ public EffectHandler effect(final ThrowingConsumer the type of exception the new effect may throw - * @param effect the checked runnable operation to execute next - * @return an {@link EffectHandler} with either the thrown exception to be - * handled or nothing - * @deprecated in favor of {@link #effect(ThrowingConsumer)} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public EffectHandler runEffect(// NOSONAR - final ThrowingConsumer effect - ) { - return this.effect(effect); - } - /** * If the value is present, cast the value to another type. In case of an * exception during the cast, a Maybe with {@link #empty()} is returned. @@ -537,17 +348,6 @@ public boolean isEmpty() { return this.value.isEmpty(); } - /** - * Checks if the {@code Maybe} is empty. That is, when no value is present. - * - * @return true if the value is not present, false otherwise - * @deprecated in favor of {@link #isEmpty()} - */ - @Deprecated(forRemoval = true, since = "3.4.0") - public boolean hasNothing() { // NOSONAR - return this.isEmpty(); - } - /** * Safely unbox the value as an {@link Optional} which may or may not contain * a value. diff --git a/src/test/java/io/github/joselion/maybe/CloseableHandlerTests.java b/src/test/java/io/github/joselion/maybe/CloseableHandlerTests.java index 0407667..a104b2a 100644 --- a/src/test/java/io/github/joselion/maybe/CloseableHandlerTests.java +++ b/src/test/java/io/github/joselion/maybe/CloseableHandlerTests.java @@ -5,7 +5,6 @@ import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import java.io.FileInputStream; @@ -139,17 +138,6 @@ } } - @Nested class resolveClosing { - @Test void calls_solve() { - final var identity = ThrowingFunction.identity(); - final var error = new IOException("Something went wrong..."); - final var handler = spy(CloseableHandler.failure(error)); - handler.resolveClosing(identity); - - verify(handler).solve(identity); - } - } - @Nested class effect { @Nested class when_the_resource_is_present { @Nested class when_the_operation_succeeds { @@ -202,15 +190,6 @@ } } - @Nested class runEffectClosing { - @Test void calls_effect() { - final var handler = spy(CloseableHandler.failure(FAIL_EXCEPTION)); - handler.runEffectClosing(noOpEffect); - - verify(handler).effect(noOpEffect); - } - } - private FileInputStream getFIS() { return Maybe.of(FILE_PATH) .solve(FileInputStream::new) diff --git a/src/test/java/io/github/joselion/maybe/EffectHandlerTests.java b/src/test/java/io/github/joselion/maybe/EffectHandlerTests.java index ffff5a4..4a31a0b 100644 --- a/src/test/java/io/github/joselion/maybe/EffectHandlerTests.java +++ b/src/test/java/io/github/joselion/maybe/EffectHandlerTests.java @@ -5,7 +5,6 @@ import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -249,19 +248,6 @@ } } - @Nested class runEffect { - @Test void calls_effect() { - final var onSuccess = Spy.>lambda(() -> { }); - final var onError = Spy.>lambda(error -> { }); - final var handler = spy(Maybe.from(throwingOp)); - handler.runEffect(onSuccess, onError); - handler.runEffect(onSuccess); - - verify(handler).effect(onSuccess, onError); - verify(handler).effect(onSuccess); - } - } - @Nested class orElse { @Nested class when_the_error_is_present { @Test void calls_the_effect_callback() { diff --git a/src/test/java/io/github/joselion/maybe/MaybeTests.java b/src/test/java/io/github/joselion/maybe/MaybeTests.java index baa038e..38ae5e1 100644 --- a/src/test/java/io/github/joselion/maybe/MaybeTests.java +++ b/src/test/java/io/github/joselion/maybe/MaybeTests.java @@ -5,10 +5,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE; import static org.assertj.core.api.InstanceOfAssertFactories.optional; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.CALLS_REAL_METHODS; -import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -89,18 +86,6 @@ } } - @Nested class just { - @Nested class calls_of { - @Test void returns_a_Maybe_wrapping_the_value() { - try (var maybe = mockStatic(Maybe.class, CALLS_REAL_METHODS)) { - Maybe.just(OK); - - maybe.verify(() -> Maybe.of(OK)); - } - } - } - } - @Nested class empty { @Test void returns_an_empty_Maybe() { final var maybe = Maybe.empty(); @@ -109,26 +94,6 @@ } } - @Nested class nothing { - @Test void calls_empty() { - try (var maybe = mockStatic(Maybe.class, CALLS_REAL_METHODS)) { - Maybe.nothing(); - - maybe.verify(() -> Maybe.empty()); - } - } - } - - @Nested class fromOptional { - @Test void calls_of() { - try (var maybe = mockStatic(Maybe.class, CALLS_REAL_METHODS)) { - Maybe.fromOptional(Optional.empty()); - - maybe.verify(() -> Maybe.of(Optional.empty())); - } - } - } - @Nested class from { @Nested class when_a_value_is_provided { @Nested class and_the_operation_succeeds { @@ -181,26 +146,6 @@ } } - @Nested class fromResolver { - @Test void calls_from() { - try (var maybe = mockStatic(Maybe.class, CALLS_REAL_METHODS)) { - Maybe.fromResolver(failSupplier); - - maybe.verify(() -> Maybe.from(failSupplier)); - } - } - } - - @Nested class fromEffect { - @Test void class_from() { - try (var maybe = mockStatic(Maybe.class, CALLS_REAL_METHODS)) { - Maybe.fromEffect(failRunnable); - - maybe.verify(() -> Maybe.from(failRunnable)); - } - } - } - @Nested class partial { @Nested class when_a_function_is_provided { @Test void returns_a_function_that_takes_a_value_and_returns_a_solve_handler() throws IOException { @@ -242,26 +187,6 @@ } } - @Nested class partialResolver { - @Test void calls_partial() { - try (var maybe = mockStatic(Maybe.class, CALLS_REAL_METHODS)) { - Maybe.partialResolver(failFunction); - - maybe.verify(() -> Maybe.partial(failFunction)); - } - } - } - - @Nested class partialEffect { - @Test void calls_partial() { - try (var maybe = mockStatic(Maybe.class, CALLS_REAL_METHODS)) { - Maybe.partialEffect(failConsumer); - - maybe.verify(() -> Maybe.partial(failConsumer)); - } - } - } - @Nested class withResource { @Test void returns_the_CloseableHandler_with_the_resource() throws FileNotFoundException, IOException { try (var fis = new FileInputStream("./src/test/resources/readTest.txt")) { @@ -397,15 +322,6 @@ } } - @Nested class resolve { - @Test void calls_solve() { - final var maybe = spy(Maybe.of(OK)); - maybe.resolve(failFunction); - - verify(maybe).solve(failFunction); - } - } - @Nested class effect { @Nested class when_the_value_is_present { @Test void the_callback_is_called_with_the_value() { @@ -459,15 +375,6 @@ } } - @Nested class runEffect { - @Test void call_effect() { - final var maybe = spy(Maybe.of(OK)); - maybe.runEffect(failConsumer); - - verify(maybe).effect(failConsumer); - } - } - @Nested class cast { @Nested class when_the_value_is_castable_to_the_passed_type { @Test void returns_a_solve_handler_with_the_cast_value() { @@ -514,15 +421,6 @@ } } - @Nested class hasNothing { - @Test void calls_isEmpty() { - final var maybe = spy(Maybe.of(OK)); - maybe.hasNothing(); - - verify(maybe).isEmpty(); - } - } - @Nested class toOptional { @Nested class when_the_value_is_present { @Test void returns_an_Optional_wrapping_the_value() { diff --git a/src/test/java/io/github/joselion/maybe/SolveHandlerTests.java b/src/test/java/io/github/joselion/maybe/SolveHandlerTests.java index 342c809..2fb0bc6 100644 --- a/src/test/java/io/github/joselion/maybe/SolveHandlerTests.java +++ b/src/test/java/io/github/joselion/maybe/SolveHandlerTests.java @@ -6,7 +6,6 @@ import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -279,18 +278,6 @@ } } - @Nested class resolve { - @Test void calls_solve() { - final var identity = ThrowingFunction.identity(); - final var handler = spy(Maybe.from(okOp)); - handler.resolve(identity, identity); - handler.resolve(identity); - - verify(handler).solve(identity); - verify(handler).solve(identity, identity); - } - } - @Nested class effect { @Nested class when_the_value_is_present { @Test void calls_the_solver_callback_and_returns_a_handler() throws FileSystemException { @@ -347,19 +334,6 @@ } } - @Nested class runEffect { - @Test void calls_effect() { - final var onSuccess = Spy.>lambda(x -> { }); - final var onError = Spy.>lambda(x -> { }); - final var maybe = spy(Maybe.from(okOp)); - maybe.runEffect(onSuccess); - maybe.runEffect(onSuccess, onError); - - verify(maybe).effect(onSuccess, onError); - verify(maybe).effect(onSuccess); - } - } - @Nested class map { @Nested class when_the_value_is_present { @Test void returns_a_handler_applying_the_mapper_function() {