aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/apache/commons/lang3
diff options
context:
space:
mode:
authorGary Gregory <garydgregory@gmail.com>2020-06-17 09:30:21 -0400
committerGary Gregory <garydgregory@gmail.com>2020-06-17 09:30:21 -0400
commit36111ba5829bdd4249c7418c1aec17c149ef86a3 (patch)
treed007c75e101be76fa1a126882f4623c593d186ee /src/test/java/org/apache/commons/lang3
parent8a2d7afd9f1be1c6cc6b5f3102b6659846fad874 (diff)
downloadapache-commons-lang-36111ba5829bdd4249c7418c1aec17c149ef86a3.tar.gz
[LANG-1568] More failable functional interfaces to match JRE functional
interfaces.
Diffstat (limited to 'src/test/java/org/apache/commons/lang3')
-rw-r--r--src/test/java/org/apache/commons/lang3/FunctionsTest.java45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/test/java/org/apache/commons/lang3/FunctionsTest.java b/src/test/java/org/apache/commons/lang3/FunctionsTest.java
index d114224f6..36ed6ca35 100644
--- a/src/test/java/org/apache/commons/lang3/FunctionsTest.java
+++ b/src/test/java/org/apache/commons/lang3/FunctionsTest.java
@@ -77,6 +77,21 @@ class FunctionsTest {
return true;
}
+ static boolean testDouble(double value) throws SomeException {
+ throwOnOdd();
+ return true;
+ }
+
+ static boolean testInt(int value) throws SomeException {
+ throwOnOdd();
+ return true;
+ }
+
+ static boolean testLong(long value) throws SomeException {
+ throwOnOdd();
+ return true;
+ }
+
private static void throwOnOdd() throws SomeException {
final int i = ++invocations;
if (i % 2 == 1) {
@@ -689,11 +704,21 @@ class FunctionsTest {
@Test
public void testConstructor() {
- // We allow this, which must be an omission to make the ctor private.
+ // We allow this, which must have been an omission to make the ctor private.
+ // We could make the ctor private in 4.0.
new Functions();
}
@Test
+ public void testDoublePredicate() throws Throwable {
+ FailureOnOddInvocations.invocations = 0;
+ final Functions.FailableDoublePredicate<Throwable> failablePredicate = t1 -> FailureOnOddInvocations
+ .testDouble(t1);
+ assertThrows(SomeException.class, () -> failablePredicate.test(1d));
+ failablePredicate.test(1d);
+ }
+
+ @Test
public void testFunction() {
final IllegalStateException ise = new IllegalStateException();
final Testable<?, ?> testable = new Testable<>(ise);
@@ -856,6 +881,24 @@ class FunctionsTest {
}
@Test
+ public void testIntPredicate() throws Throwable {
+ FailureOnOddInvocations.invocations = 0;
+ final Functions.FailableIntPredicate<Throwable> failablePredicate = t1 -> FailureOnOddInvocations
+ .testInt(t1);
+ assertThrows(SomeException.class, () -> failablePredicate.test(1));
+ failablePredicate.test(1);
+ }
+
+ @Test
+ public void testLongPredicate() throws Throwable {
+ FailureOnOddInvocations.invocations = 0;
+ final Functions.FailableLongPredicate<Throwable> failablePredicate = t1 -> FailureOnOddInvocations
+ .testLong(t1);
+ assertThrows(SomeException.class, () -> failablePredicate.test(1l));
+ failablePredicate.test(1l);
+ }
+
+ @Test
@DisplayName("Test that asPredicate(FailablePredicate) is converted to -> Predicate ")
public void testPredicate() {
FailureOnOddInvocations.invocations = 0;