You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/06/12 15:35:41 UTC
[commons-lang] branch master updated: [LANG-1568]
FailableBooleanSupplier, FailableIntSupplier, FailableLongSupplier,
FailableDoubleSupplier.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new d88f70e [LANG-1568] FailableBooleanSupplier, FailableIntSupplier, FailableLongSupplier, FailableDoubleSupplier.
d88f70e is described below
commit d88f70e8ff3e73981809ddc530c19288c1f092c5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jun 12 11:35:37 2020 -0400
[LANG-1568] FailableBooleanSupplier, FailableIntSupplier,
FailableLongSupplier, FailableDoubleSupplier.
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/lang3/Functions.java | 144 ++++++++++-
.../org/apache/commons/lang3/FunctionsTest.java | 275 +++++++++++++++++----
3 files changed, 367 insertions(+), 53 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2204f32..a51e645 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -60,6 +60,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="XenoAmess, Gary Gregory">Add ArrayUtils.isSameLength() to compare more array types #430.</action>
<action issue="LANG-1545" type="update" dev="ggregory" due-to="XenoAmess, Gary Gregory">CharSequenceUtils.regionMatches is wrong dealing with Georgian.</action>
<action type="add" dev="jochen">Added the Locks class as a convenient possibility to deal with locked objects.</action>
+ <action issue="LANG-1568" type="add" dev="ggregory">Add to Functions: FailableBooleanSupplier, FailableIntSupplier, FailableLongSupplier, FailableDoubleSupplier.</action>
</release>
<release version="3.10" date="2020-03-22" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11.">
diff --git a/src/main/java/org/apache/commons/lang3/Functions.java b/src/main/java/org/apache/commons/lang3/Functions.java
index 12749ea..ae03211 100644
--- a/src/main/java/org/apache/commons/lang3/Functions.java
+++ b/src/main/java/org/apache/commons/lang3/Functions.java
@@ -25,8 +25,12 @@ import java.util.concurrent.Callable;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
+import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
+import java.util.function.DoubleSupplier;
import java.util.function.Function;
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
@@ -235,13 +239,85 @@ public class Functions {
/**
* Supplies an object
*
- * @return the suppliers result
+ * @return a result
* @throws T if the supplier fails
*/
R get() throws T;
}
/**
+ * A functional interface like {@link BooleanSupplier} that declares a Throwable.
+ *
+ * @param <T> Thrown exception.
+ * @since 3.11
+ */
+ @FunctionalInterface
+ public interface FailableBooleanSupplier<T extends Throwable> {
+
+ /**
+ * Supplies a boolean.
+ *
+ * @return a result
+ * @throws T if the supplier fails
+ */
+ boolean getAsBoolean() throws T;
+ }
+
+ /**
+ * A functional interface like {@link DoubleSupplier} that declares a Throwable.
+ *
+ * @param <T> Thrown exception.
+ * @since 3.11
+ */
+ @FunctionalInterface
+ public interface FailableDoubleSupplier<T extends Throwable> {
+
+ /**
+ * Supplies a double.
+ *
+ * @return a result
+ * @throws T if the supplier fails
+ */
+ double getAsDouble() throws T;
+ }
+
+ /**
+ * A functional interface like {@link IntSupplier} that declares a Throwable.
+ *
+ * @param <T> Thrown exception.
+ * @since 3.11
+ */
+ @FunctionalInterface
+ public interface FailableIntSupplier<T extends Throwable> {
+
+ /**
+ * Supplies an int.
+ *
+ * @return a result
+ * @throws T if the supplier fails
+ */
+ int getAsInt() throws T;
+ }
+
+ /**
+ * A functional interface like {@link LongSupplier} that declares a Throwable.
+ *
+ * @param <T> Thrown exception.
+ * @since 3.11
+ */
+ @FunctionalInterface
+ public interface FailableLongSupplier<T extends Throwable> {
+
+ /**
+ * Supplies a long.
+ *
+ * @return a result
+ * @throws T if the supplier fails
+ */
+ long getAsLong() throws T;
+ }
+
+ /**
* Consumes a consumer and rethrows any exception as a {@link RuntimeException}.
*
* @param consumer the consumer to consume
@@ -424,7 +500,7 @@ public class Functions {
}
/**
- * Invokes the supplier, and returns the result.
+ * Invokes a supplier, and returns the result.
*
* @param supplier The supplier to invoke.
* @param <O> The suppliers output type.
@@ -441,6 +517,70 @@ public class Functions {
}
/**
+ * Invokes a boolean supplier, and returns the result.
+ *
+ * @param supplier The boolean supplier to invoke.
+ * @param <T> The type of checked exception, which the supplier can throw.
+ * @return The boolean, which has been created by the supplier
+ * @since 3.11
+ */
+ public static <T extends Throwable> boolean getAsBoolean(final FailableBooleanSupplier<T> supplier) {
+ try {
+ return supplier.getAsBoolean();
+ } catch (final Throwable t) {
+ throw rethrow(t);
+ }
+ }
+
+ /**
+ * Invokes a double supplier, and returns the result.
+ *
+ * @param supplier The double supplier to invoke.
+ * @param <T> The type of checked exception, which the supplier can throw.
+ * @return The boolean, which has been created by the supplier
+ * @since 3.11
+ */
+ public static <T extends Throwable> double getAsDouble(final FailableDoubleSupplier<T> supplier) {
+ try {
+ return supplier.getAsDouble();
+ } catch (final Throwable t) {
+ throw rethrow(t);
+ }
+ }
+
+ /**
+ * Invokes an int supplier, and returns the result.
+ *
+ * @param supplier The int supplier to invoke.
+ * @param <T> The type of checked exception, which the supplier can throw.
+ * @return The boolean, which has been created by the supplier
+ * @since 3.11
+ */
+ public static <T extends Throwable> int getAsInt(final FailableIntSupplier<T> supplier) {
+ try {
+ return supplier.getAsInt();
+ } catch (final Throwable t) {
+ throw rethrow(t);
+ }
+ }
+
+ /**
+ * Invokes a long supplier, and returns the result.
+ *
+ * @param supplier The long supplier to invoke.
+ * @param <T> The type of checked exception, which the supplier can throw.
+ * @return The boolean, which has been created by the supplier
+ * @since 3.11
+ */
+ public static <T extends Throwable> long getAsLong(final FailableLongSupplier<T> supplier) {
+ try {
+ return supplier.getAsLong();
+ } catch (final Throwable t) {
+ throw rethrow(t);
+ }
+ }
+
+ /**
* <p>
* Rethrows a {@link Throwable} as an unchecked exception. If the argument is already unchecked, namely a
* {@code RuntimeException} or {@code Error} then the argument will be rethrown without modification. If the
diff --git a/src/test/java/org/apache/commons/lang3/FunctionsTest.java b/src/test/java/org/apache/commons/lang3/FunctionsTest.java
index 4180829..63375cd 100644
--- a/src/test/java/org/apache/commons/lang3/FunctionsTest.java
+++ b/src/test/java/org/apache/commons/lang3/FunctionsTest.java
@@ -16,14 +16,12 @@
*/
package org.apache.commons.lang3;
-import org.apache.commons.lang3.Functions.FailableBiConsumer;
-import org.apache.commons.lang3.Functions.FailableBiFunction;
-import org.apache.commons.lang3.Functions.FailableCallable;
-import org.apache.commons.lang3.Functions.FailableConsumer;
-import org.apache.commons.lang3.Functions.FailableFunction;
-import org.apache.commons.lang3.Functions.FailableSupplier;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -37,24 +35,29 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.apache.commons.lang3.Functions.FailableBiConsumer;
+import org.apache.commons.lang3.Functions.FailableBiFunction;
+import org.apache.commons.lang3.Functions.FailableCallable;
+import org.apache.commons.lang3.Functions.FailableConsumer;
+import org.apache.commons.lang3.Functions.FailableFunction;
+import org.apache.commons.lang3.Functions.FailableSupplier;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
class FunctionsTest {
+
public static class SomeException extends Exception {
+
private static final long serialVersionUID = -4965704778119283411L;
private Throwable t;
- SomeException(final String pMsg) {
- super(pMsg);
+ SomeException(final String message) {
+ super(message);
}
- public void setThrowable(final Throwable pThrowable) {
- t = pThrowable;
+ public void setThrowable(final Throwable throwable) {
+ t = throwable;
}
public void test() throws Throwable {
@@ -63,6 +66,7 @@ class FunctionsTest {
}
}
}
+
public static class Testable {
private Throwable t;
@@ -70,48 +74,99 @@ class FunctionsTest {
t = pTh;
}
- public void setThrowable(final Throwable pThrowable) {
- t = pThrowable;
+ public void setThrowable(final Throwable throwable) {
+ t = throwable;
}
public void test() throws Throwable {
test(t);
}
- public void test(final Throwable pThrowable) throws Throwable {
- if (pThrowable != null) {
- throw pThrowable;
+ public void test(final Throwable throwable) throws Throwable {
+ if (throwable != null) {
+ throw throwable;
+ }
+ }
+
+ public Integer testInteger() throws Throwable {
+ return testInteger(t);
+ }
+
+ public int testIntPrimitive() throws Throwable {
+ return testIntPrimitive(t);
+ }
+
+ public long testLongPrimitive() throws Throwable {
+ return testLongPrimitive(t);
+ }
+
+ public boolean testBooleanPrimitive() throws Throwable {
+ return testBooleanPrimitive(t);
+ }
+
+ public double testDoublePrimitive() throws Throwable {
+ return testDoublePrimitive(t);
+ }
+
+ public Integer testInteger(final Throwable throwable) throws Throwable {
+ if (throwable != null) {
+ throw throwable;
}
+ return 0;
}
- public Integer testInt() throws Throwable {
- return testInt(t);
+ public int testIntPrimitive(final Throwable throwable) throws Throwable {
+ if (throwable != null) {
+ throw throwable;
+ }
+ return 0;
}
- public Integer testInt(final Throwable pThrowable) throws Throwable {
- if (pThrowable != null) {
- throw pThrowable;
+ public double testDoublePrimitive(final Throwable throwable) throws Throwable {
+ if (throwable != null) {
+ throw throwable;
}
return 0;
}
+
+ public long testLongPrimitive(final Throwable throwable) throws Throwable {
+ if (throwable != null) {
+ throw throwable;
+ }
+ return 0;
+ }
+
+ public boolean testBooleanPrimitive(final Throwable throwable) throws Throwable {
+ if (throwable != null) {
+ throw throwable;
+ }
+ return false;
+ }
}
public static class FailureOnOddInvocations {
- private static int invocation;
+ private static int invocations;
private static void throwOnOdd() throws SomeException {
- final int i = ++invocation;
+ final int i = ++invocations;
if (i % 2 == 1) {
throw new SomeException("Odd Invocation: " + i);
}
}
+
static boolean failingBool() throws SomeException {
throwOnOdd();
return true;
}
+
FailureOnOddInvocations() throws SomeException {
throwOnOdd();
}
+
+ boolean getAsBoolean() throws SomeException {
+ throwOnOdd();
+ return true;
+ }
}
public static class CloseableObject {
@@ -138,20 +193,20 @@ class FunctionsTest {
@Test
void testRunnable() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final Throwable cause = e.getCause();
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
assertEquals("Odd Invocation: 1", cause.getMessage());
- // Even invocation, should not throw an exception
+ // Even invocations, should not throw an exception
Functions.run(FailureOnOddInvocations::new);
}
@Test
void testAsRunnable() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final Runnable runnable = Functions.asRunnable(FailureOnOddInvocations::new);
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> runnable.run());
final Throwable cause = e.getCause();
@@ -159,13 +214,13 @@ class FunctionsTest {
assertTrue(cause instanceof SomeException);
assertEquals("Odd Invocation: 1", cause.getMessage());
- // Even invocation, should not throw an exception
+ // Even invocations, should not throw an exception
runnable.run();
}
@Test
void testCallable() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final Throwable cause = e.getCause();
assertNotNull(cause);
@@ -177,7 +232,7 @@ class FunctionsTest {
@Test
void testAsCallable() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final FailableCallable<FailureOnOddInvocations, SomeException> failableCallable = FailureOnOddInvocations::new;
final Callable<FailureOnOddInvocations> callable = Functions.asCallable(failableCallable);
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> callable.call());
@@ -292,23 +347,23 @@ class FunctionsTest {
public void testApplyFunction() {
final IllegalStateException ise = new IllegalStateException();
final Testable testable = new Testable(ise);
- Throwable e = assertThrows(IllegalStateException.class, () -> Functions.apply(Testable::testInt, testable));
+ Throwable e = assertThrows(IllegalStateException.class, () -> Functions.apply(Testable::testInteger, testable));
assertSame(ise, e);
final Error error = new OutOfMemoryError();
testable.setThrowable(error);
- e = assertThrows(OutOfMemoryError.class, () -> Functions.apply(Testable::testInt, testable));
+ e = assertThrows(OutOfMemoryError.class, () -> Functions.apply(Testable::testInteger, testable));
assertSame(error, e);
final IOException ioe = new IOException("Unknown I/O error");
testable.setThrowable(ioe);
- e = assertThrows(UncheckedIOException.class, () -> Functions.apply(Testable::testInt, testable));
+ e = assertThrows(UncheckedIOException.class, () -> Functions.apply(Testable::testInteger, testable));
final Throwable t = e.getCause();
assertNotNull(t);
assertSame(ioe, t);
testable.setThrowable(null);
- final Integer i = Functions.apply(Testable::testInt, testable);
+ final Integer i = Functions.apply(Testable::testInteger, testable);
assertNotNull(i);
assertEquals(0, i.intValue());
}
@@ -319,7 +374,7 @@ class FunctionsTest {
final Testable testable = new Testable(ise);
final FailableFunction<Throwable, Integer, Throwable> failableFunction = th -> {
testable.setThrowable(th);
- return Integer.valueOf(testable.testInt());
+ return Integer.valueOf(testable.testInteger());
};
final Function<Throwable, Integer> function = Functions.asFunction(failableFunction);
Throwable e = assertThrows(IllegalStateException.class, () -> function.apply(ise));
@@ -344,20 +399,20 @@ class FunctionsTest {
public void testApplyBiFunction() {
final IllegalStateException ise = new IllegalStateException();
final Testable testable = new Testable(null);
- Throwable e = assertThrows(IllegalStateException.class, () -> Functions.apply(Testable::testInt, testable, ise));
+ Throwable e = assertThrows(IllegalStateException.class, () -> Functions.apply(Testable::testInteger, testable, ise));
assertSame(ise, e);
final Error error = new OutOfMemoryError();
- e = assertThrows(OutOfMemoryError.class, () -> Functions.apply(Testable::testInt, testable, error));
+ e = assertThrows(OutOfMemoryError.class, () -> Functions.apply(Testable::testInteger, testable, error));
assertSame(error, e);
final IOException ioe = new IOException("Unknown I/O error");
- e = assertThrows(UncheckedIOException.class, () -> Functions.apply(Testable::testInt, testable, ioe));
+ e = assertThrows(UncheckedIOException.class, () -> Functions.apply(Testable::testInteger, testable, ioe));
final Throwable t = e.getCause();
assertNotNull(t);
assertSame(ioe, t);
- final Integer i = Functions.apply(Testable::testInt, testable, (Throwable) null);
+ final Integer i = Functions.apply(Testable::testInteger, testable, (Throwable) null);
assertNotNull(i);
assertEquals(0, i.intValue());
}
@@ -368,7 +423,7 @@ class FunctionsTest {
final Testable testable = new Testable(ise);
final FailableBiFunction<Testable, Throwable, Integer, Throwable> failableBiFunction = (t, th) -> {
t.setThrowable(th);
- return Integer.valueOf(t.testInt());
+ return Integer.valueOf(t.testInteger());
};
final BiFunction<Testable, Throwable, Integer> biFunction = Functions.asBiFunction(failableBiFunction);
Throwable e = assertThrows(IllegalStateException.class, () -> biFunction.apply(testable, ise));
@@ -391,7 +446,7 @@ class FunctionsTest {
@Test
public void testGetFromSupplier() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> Functions.run(FailureOnOddInvocations::new));
final Throwable cause = e.getCause();
assertNotNull(cause);
@@ -402,9 +457,128 @@ class FunctionsTest {
}
@Test
+ public void testGetSupplier() {
+ final IllegalStateException ise = new IllegalStateException();
+ final Testable testable = new Testable(ise);
+ Throwable e = assertThrows(IllegalStateException.class, () -> Functions.get(testable::testInteger));
+ assertSame(ise, e);
+
+ final Error error = new OutOfMemoryError();
+ testable.setThrowable(error);
+ e = assertThrows(OutOfMemoryError.class, () -> Functions.get(testable::testInteger));
+ assertSame(error, e);
+
+ final IOException ioe = new IOException("Unknown I/O error");
+ testable.setThrowable(ioe);
+ e = assertThrows(UncheckedIOException.class, () -> Functions.get(testable::testInteger));
+ final Throwable t = e.getCause();
+ assertNotNull(t);
+ assertSame(ioe, t);
+
+ testable.setThrowable(null);
+ final Integer i = Functions.apply(Testable::testInteger, testable);
+ assertNotNull(i);
+ assertEquals(0, i.intValue());
+ }
+
+ @Test
+ public void testGetAsBooleanSupplier() {
+ final IllegalStateException ise = new IllegalStateException();
+ final Testable testable = new Testable(ise);
+ Throwable e = assertThrows(IllegalStateException.class, () -> Functions.getAsBoolean(testable::testBooleanPrimitive));
+ assertSame(ise, e);
+
+ final Error error = new OutOfMemoryError();
+ testable.setThrowable(error);
+ e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsBoolean(testable::testBooleanPrimitive));
+ assertSame(error, e);
+
+ final IOException ioe = new IOException("Unknown I/O error");
+ testable.setThrowable(ioe);
+ e = assertThrows(UncheckedIOException.class, () -> Functions.getAsBoolean(testable::testBooleanPrimitive));
+ final Throwable t = e.getCause();
+ assertNotNull(t);
+ assertSame(ioe, t);
+
+ testable.setThrowable(null);
+ assertFalse(Functions.getAsBoolean(testable::testBooleanPrimitive));
+ }
+
+ @Test
+ public void testGetAsDoubleSupplier() {
+ final IllegalStateException ise = new IllegalStateException();
+ final Testable testable = new Testable(ise);
+ Throwable e = assertThrows(IllegalStateException.class, () -> Functions.getAsDouble(testable::testDoublePrimitive));
+ assertSame(ise, e);
+
+ final Error error = new OutOfMemoryError();
+ testable.setThrowable(error);
+ e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsDouble(testable::testDoublePrimitive));
+ assertSame(error, e);
+
+ final IOException ioe = new IOException("Unknown I/O error");
+ testable.setThrowable(ioe);
+ e = assertThrows(UncheckedIOException.class, () -> Functions.getAsDouble(testable::testDoublePrimitive));
+ final Throwable t = e.getCause();
+ assertNotNull(t);
+ assertSame(ioe, t);
+
+ testable.setThrowable(null);
+ assertEquals(0, Functions.getAsDouble(testable::testDoublePrimitive));
+ }
+
+ @Test
+ public void testGetAsIntSupplier() {
+ final IllegalStateException ise = new IllegalStateException();
+ final Testable testable = new Testable(ise);
+ Throwable e = assertThrows(IllegalStateException.class, () -> Functions.getAsInt(testable::testIntPrimitive));
+ assertSame(ise, e);
+
+ final Error error = new OutOfMemoryError();
+ testable.setThrowable(error);
+ e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsInt(testable::testIntPrimitive));
+ assertSame(error, e);
+
+ final IOException ioe = new IOException("Unknown I/O error");
+ testable.setThrowable(ioe);
+ e = assertThrows(UncheckedIOException.class, () -> Functions.getAsInt(testable::testIntPrimitive));
+ final Throwable t = e.getCause();
+ assertNotNull(t);
+ assertSame(ioe, t);
+
+ testable.setThrowable(null);
+ final int i = Functions.getAsInt(testable::testInteger);
+ assertEquals(0, i);
+ }
+
+ @Test
+ public void testGetAsLongSupplier() {
+ final IllegalStateException ise = new IllegalStateException();
+ final Testable testable = new Testable(ise);
+ Throwable e = assertThrows(IllegalStateException.class, () -> Functions.getAsLong(testable::testLongPrimitive));
+ assertSame(ise, e);
+
+ final Error error = new OutOfMemoryError();
+ testable.setThrowable(error);
+ e = assertThrows(OutOfMemoryError.class, () -> Functions.getAsLong(testable::testLongPrimitive));
+ assertSame(error, e);
+
+ final IOException ioe = new IOException("Unknown I/O error");
+ testable.setThrowable(ioe);
+ e = assertThrows(UncheckedIOException.class, () -> Functions.getAsLong(testable::testLongPrimitive));
+ final Throwable t = e.getCause();
+ assertNotNull(t);
+ assertSame(ioe, t);
+
+ testable.setThrowable(null);
+ final long i = Functions.getAsLong(testable::testLongPrimitive);
+ assertEquals(0, i);
+ }
+
+ @Test
@DisplayName("Test that asPredicate(FailablePredicate) is converted to -> Predicate ")
public void testAsPredicate() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final Functions.FailablePredicate<Object, Throwable> failablePredicate = t -> FailureOnOddInvocations.failingBool();
final Predicate<?> predicate = Functions.asPredicate(failablePredicate);
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null));
@@ -419,7 +593,7 @@ class FunctionsTest {
@Test
@DisplayName("Test that asPredicate(FailableBiPredicate) is converted to -> BiPredicate ")
public void testAsBiPredicate() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final Functions.FailableBiPredicate<Object, Object, Throwable> failableBiPredicate = (t1, t2) -> FailureOnOddInvocations.failingBool();
final BiPredicate<?, ?> predicate = Functions.asBiPredicate(failableBiPredicate);
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> predicate.test(null, null));
@@ -433,7 +607,7 @@ class FunctionsTest {
@Test
public void testAsSupplier() {
- FailureOnOddInvocations.invocation = 0;
+ FailureOnOddInvocations.invocations = 0;
final FailableSupplier<FailureOnOddInvocations, Throwable> failableSupplier = FailureOnOddInvocations::new;
final Supplier<FailureOnOddInvocations> supplier = Functions.asSupplier(failableSupplier);
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> supplier.get());
@@ -441,8 +615,7 @@ class FunctionsTest {
assertNotNull(cause);
assertTrue(cause instanceof SomeException);
assertEquals("Odd Invocation: 1", cause.getMessage());
- final FailureOnOddInvocations instance = supplier.get();
- assertNotNull(instance);
+ assertNotNull(supplier.get());
}
@Test