diff --git a/src/main/java/org/cactoos/func/FuncWithFallback.java b/src/main/java/org/cactoos/func/FuncWithFallback.java index e0a20f6f62..1dfa8925b1 100644 --- a/src/main/java/org/cactoos/func/FuncWithFallback.java +++ b/src/main/java/org/cactoos/func/FuncWithFallback.java @@ -48,7 +48,7 @@ * {@code * final Product product = new FuncWithFallback<>( * id -> new SqlProduct().apply(id), - * new FallbackFrom<>( + * new Fallback.From<>( * SQLException.class, * id -> new CachedProduct().apply(id) * ) @@ -70,11 +70,11 @@ * final Product product = new FuncWithFallback<>( * id -> new SqlProduct().apply(id), * new IterableOf<>( - * new FallbackFrom<>( + * new Fallback.From<>( * SQLException.class, * id -> new CachedProduct().apply(id) * ), - * new FallbackFrom<>( + * new Fallback.From<>( * SQLRecoverableException.class, * id -> new SqlProduct().apply(id) // run it again * ) @@ -105,11 +105,11 @@ public final class FuncWithFallback implements Func { /** * Ctor. * @param fnc The func - * @param fbk The fallback + * @param fbks The fallbacks */ - @SuppressWarnings("unchecked") - public FuncWithFallback(final Func fnc, final Fallback fbk) { - this(fnc, new IterableOf<>(fbk)); + @SafeVarargs + public FuncWithFallback(final Func fnc, final Fallback... fbks) { + this(fnc, new IterableOf<>(fbks)); } /** diff --git a/src/test/java/org/cactoos/func/FuncWithFallbackTest.java b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java index 2c4e4dbb8f..5d0709fd8e 100644 --- a/src/test/java/org/cactoos/func/FuncWithFallbackTest.java +++ b/src/test/java/org/cactoos/func/FuncWithFallbackTest.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.util.IllegalFormatException; import java.util.IllegalFormatWidthException; +import org.cactoos.Fallback; import org.cactoos.iterable.IterableOf; import org.junit.Test; import org.llorllale.cactoos.matchers.Assertion; @@ -46,9 +47,9 @@ public void usesMainFunc() { final String expected = "It's success"; new Assertion<>( "Can't use the main function if no exception", - new FuncWithFallback<>( + new FuncWithFallback( input -> expected, - new FallbackFrom<>( + new Fallback.From<>( Exception.class, ex -> "In case of failure..." ) @@ -62,11 +63,11 @@ public void usesFallback() { final String expected = "Never mind"; new Assertion<>( "Can't use the callback in case of exception", - new FuncWithFallback<>( + new FuncWithFallback( input -> { throw new IOException("Failure"); }, - new FallbackFrom<>(IOException.class, ex -> expected) + new Fallback.From<>(IOException.class, ex -> expected) ), new FuncApplies<>(1, expected) ).affirm(); @@ -77,13 +78,13 @@ public void usesFallbackOfInterruptedException() { final String expected = "Fallback from InterruptedException"; new Assertion<>( "Can't use a fallback from Interrupted in case of exception", - new FuncWithFallback<>( + new FuncWithFallback( input -> { throw new InterruptedException( "Failure with InterruptedException" ); }, - new FallbackFrom<>(InterruptedException.class, exp -> expected) + new Fallback.From<>(InterruptedException.class, exp -> expected) ), new FuncApplies<>(1, expected) ).affirm(); @@ -99,11 +100,11 @@ public void usesTheClosestFallback() { throw new IllegalFormatWidthException(1); }, new IterableOf<>( - new FallbackFrom<>( + new Fallback.From<>( IllegalArgumentException.class, exp -> "Fallback from IllegalArgumentException" ), - new FallbackFrom<>( + new Fallback.From<>( IllegalFormatException.class, exp -> expected )