This is an automated email from the ASF dual-hosted git repository.
garydgregory 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 19e2d568a Add standalone functions test classes (#1642)
19e2d568a is described below
commit 19e2d568a4ee4910ff470eba40ec040673195d7d
Author: Gary Gregory <[email protected]>
AuthorDate: Sat May 9 20:00:51 2026 -0400
Add standalone functions test classes (#1642)
* Add FailableConsumer.accept(FailableConsumer<T, E>, T)
Add missing test class
* Add standalone test classes for interfaces in
org.apache.commons.lang3.function
---
.../lang3/function/FailableBiFunctionTest.java | 85 +++++++++++++++++
.../lang3/function/FailableBiPredicateTest.java | 105 +++++++++++++++++++++
.../function/FailableBooleanSupplierTest.java | 56 +++++++++++
.../lang3/function/FailableByteConsumerTest.java | 94 ++++++++++++++++++
...lierTest.java => FailableByteSupplierTest.java} | 33 ++++---
...SupplierTest.java => FailableCallableTest.java} | 33 ++++---
....java => FailableDoubleBinaryOperatorTest.java} | 33 ++++---
.../lang3/function/FailableDoubleConsumerTest.java | 94 ++++++++++++++++++
...erTest.java => FailableDoubleFunctionTest.java} | 31 ++++--
.../function/FailableDoublePredicateTest.java | 105 +++++++++++++++++++++
...erTest.java => FailableDoubleSupplierTest.java} | 33 ++++---
.../function/FailableDoubleToIntFunctionTest.java | 59 ++++++++++++
.../function/FailableDoubleToLongFunctionTest.java | 59 ++++++++++++
.../function/FailableDoubleUnaryOperatorTest.java | 91 ++++++++++++++++++
.../lang3/function/FailableFunctionTest.java | 101 ++++++++++++++++++++
...est.java => FailableIntBinaryOperatorTest.java} | 33 ++++---
.../lang3/function/FailableIntConsumerTest.java | 94 ++++++++++++++++++
...plierTest.java => FailableIntFunctionTest.java} | 31 ++++--
.../lang3/function/FailableIntPredicateTest.java | 105 +++++++++++++++++++++
...plierTest.java => FailableIntSupplierTest.java} | 33 ++++---
.../function/FailableIntToDoubleFunctionTest.java | 59 ++++++++++++
.../function/FailableIntToFloatFunctionTest.java | 59 ++++++++++++
.../function/FailableIntToLongFunctionTest.java | 59 ++++++++++++
.../function/FailableIntUnaryOperatorTest.java | 91 ++++++++++++++++++
...st.java => FailableLongBinaryOperatorTest.java} | 33 ++++---
.../lang3/function/FailableLongConsumerTest.java | 94 ++++++++++++++++++
...lierTest.java => FailableLongFunctionTest.java} | 31 ++++--
.../lang3/function/FailableLongPredicateTest.java | 105 +++++++++++++++++++++
...lierTest.java => FailableLongSupplierTest.java} | 33 ++++---
.../function/FailableLongToDoubleFunctionTest.java | 59 ++++++++++++
.../function/FailableLongToIntFunctionTest.java | 59 ++++++++++++
.../function/FailableLongUnaryOperatorTest.java | 91 ++++++++++++++++++
.../function/FailableObjDoubleConsumerTest.java | 67 +++++++++++++
.../lang3/function/FailableObjIntConsumerTest.java | 68 +++++++++++++
.../function/FailableObjLongConsumerTest.java | 68 +++++++++++++
.../lang3/function/FailablePredicateTest.java | 105 +++++++++++++++++++++
...SupplierTest.java => FailableRunnableTest.java} | 37 ++++----
...ierTest.java => FailableShortSupplierTest.java} | 33 ++++---
.../lang3/function/FailableSupplierTest.java | 20 ++++
.../function/FailableToBooleanFunctionTest.java | 62 ++++++++++++
.../function/FailableToDoubleBiFunctionTest.java | 59 ++++++++++++
.../function/FailableToDoubleFunctionTest.java | 59 ++++++++++++
.../function/FailableToIntBiFunctionTest.java | 59 ++++++++++++
.../lang3/function/FailableToIntFunctionTest.java | 59 ++++++++++++
.../function/FailableToLongBiFunctionTest.java | 59 ++++++++++++
.../lang3/function/FailableToLongFunctionTest.java | 59 ++++++++++++
46 files changed, 2695 insertions(+), 200 deletions(-)
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableBiFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableBiFunctionTest.java
new file mode 100644
index 000000000..80bbf11c7
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableBiFunctionTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableBiFunction}.
+ */
+class FailableBiFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testAndThen_composesCorrectly() throws IOException {
+ final FailableBiFunction<Integer, Integer, Integer, IOException> sum =
(a, b) -> a + b;
+ final FailableFunction<Integer, String, IOException> toStr = i ->
"result:" + i;
+ assertEquals("result:3", sum.andThen(toStr).apply(1, 2));
+ }
+
+ @Test
+ void testAndThen_firstThrows_secondNotInvoked() {
+ final IOException expected = new IOException("first");
+ final FailableBiFunction<String, String, String, IOException> f = (a,
b) -> {
+ throw expected;
+ };
+ final FailableFunction<String, String, IOException> after = s -> s +
"!";
+ final IOException thrown = assertThrows(IOException.class, () ->
f.andThen(after).apply("a", "b"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableBiFunction<String, String, String, IOException> f = (a,
b) -> a + b;
+ assertNullPointerException(() -> f.andThen(null));
+ }
+
+ @Test
+ void testApply_returnsResult() throws IOException {
+ final FailableBiFunction<String, String, String, IOException> f = (a,
b) -> a + b;
+ assertEquals("ab", f.apply("a", "b"));
+ }
+
+ @Test
+ void testApply_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableBiFunction<String, String, String, IOException> f = (a,
b) -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.apply("a", "b"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyReturnsNull() throws Throwable {
+ assertNull(FailableBiFunction.nop().apply("a", "b"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableBiFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableBiPredicateTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableBiPredicateTest.java
new file mode 100644
index 000000000..93755db22
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableBiPredicateTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableBiPredicate}.
+ */
+class FailableBiPredicateTest extends AbstractLangTest {
+
+ @Test
+ void testAnd_bothTrue_returnsTrue() throws IOException {
+ final FailableBiPredicate<String, String, IOException> p = (a, b) ->
true;
+ assertTrue(p.and((a, b) -> true).test("x", "y"));
+ }
+
+ @Test
+ void testAnd_firstFalse_returnsFalse() throws IOException {
+ final FailableBiPredicate<String, String, IOException> p = (a, b) ->
false;
+ assertFalse(p.and((a, b) -> true).test("x", "y"));
+ }
+
+ @Test
+ void testAnd_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableBiPredicate<String, String, IOException> p = (a, b) ->
true;
+ assertNullPointerException(() -> p.and(null));
+ }
+
+ @Test
+ void testFalsePredicate_returnsFalse() throws Throwable {
+ assertFalse(FailableBiPredicate.falsePredicate().test("a", "b"));
+ }
+
+ @Test
+ void testNegate_invertsResult() throws IOException {
+ final FailableBiPredicate<String, String, IOException> p = (a, b) ->
true;
+ assertFalse(p.negate().test("x", "y"));
+ assertTrue(p.negate().negate().test("x", "y"));
+ }
+
+ @Test
+ void testOr_bothFalse_returnsFalse() throws IOException {
+ final FailableBiPredicate<String, String, IOException> p = (a, b) ->
false;
+ assertFalse(p.or((a, b) -> false).test("x", "y"));
+ }
+
+ @Test
+ void testOr_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableBiPredicate<String, String, IOException> p = (a, b) ->
false;
+ assertNullPointerException(() -> p.or(null));
+ }
+
+ @Test
+ void testOr_oneTrue_returnsTrue() throws IOException {
+ final FailableBiPredicate<String, String, IOException> p = (a, b) ->
false;
+ assertTrue(p.or((a, b) -> true).test("x", "y"));
+ }
+
+ @Test
+ void testTest_evaluatesCorrectly() throws IOException {
+ final FailableBiPredicate<String, String, IOException> eq =
String::equals;
+ assertTrue(eq.test("x", "x"));
+ assertFalse(eq.test("x", "y"));
+ }
+
+ @Test
+ void testTest_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableBiPredicate<String, String, IOException> p = (a, b) -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
p.test("a", "b"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testTruePredicate_returnsTrue() throws Throwable {
+ assertTrue(FailableBiPredicate.truePredicate().test("a", "b"));
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableBooleanSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableBooleanSupplierTest.java
new file mode 100644
index 000000000..90322d274
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableBooleanSupplierTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableBooleanSupplier}.
+ */
+class FailableBooleanSupplierTest extends AbstractLangTest {
+
+ @Test
+ void testGetAsBoolean_returnsFalse() throws IOException {
+ final FailableBooleanSupplier<IOException> supplier = () -> false;
+ assertFalse(supplier.getAsBoolean());
+ }
+
+ @Test
+ void testGetAsBoolean_returnsTrue() throws IOException {
+ final FailableBooleanSupplier<IOException> supplier = () -> true;
+ assertTrue(supplier.getAsBoolean());
+ }
+
+ @Test
+ void testGetAsBoolean_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableBooleanSupplier<IOException> supplier = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
supplier::getAsBoolean);
+ assertEquals(expected, thrown);
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableByteConsumerTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableByteConsumerTest.java
new file mode 100644
index 000000000..9e97c93f3
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableByteConsumerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableByteConsumer}.
+ */
+class FailableByteConsumerTest extends AbstractLangTest {
+
+ @Test
+ void testAccept_invokesConsumer() throws IOException {
+ final AtomicInteger ref = new AtomicInteger();
+ final FailableByteConsumer<IOException> consumer = v -> ref.set(v);
+ consumer.accept((byte) 42);
+ assertEquals(42, ref.get());
+ }
+
+ @Test
+ void testAccept_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableByteConsumer<IOException> consumer = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
consumer.accept((byte) 1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testAndThen_bothInvoked() throws IOException {
+ final AtomicInteger ref1 = new AtomicInteger();
+ final AtomicInteger ref2 = new AtomicInteger();
+ final FailableByteConsumer<IOException> first = v -> ref1.set(v);
+ final FailableByteConsumer<IOException> second = v -> ref2.set(v);
+ first.andThen(second).accept((byte) 7);
+ assertEquals(7, ref1.get());
+ assertEquals(7, ref2.get());
+ }
+
+ @Test
+ void testAndThen_firstThrows_secondNotInvoked() {
+ final IOException expected = new IOException("first");
+ final AtomicInteger ref = new AtomicInteger();
+ final FailableByteConsumer<IOException> throwing = v -> {
+ throw expected;
+ };
+ final FailableByteConsumer<IOException> second = v -> ref.set(v);
+ final IOException thrown = assertThrows(IOException.class, () ->
throwing.andThen(second).accept((byte) 1));
+ assertEquals(expected, thrown);
+ assertEquals(0, ref.get());
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableByteConsumer<IOException> consumer = v -> {
+ };
+ assertNullPointerException(() -> consumer.andThen(null));
+ }
+
+ @Test
+ void testNop_acceptDoesNothing() throws Throwable {
+ FailableByteConsumer.nop().accept((byte) 1);
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableByteConsumer.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableByteSupplierTest.java
similarity index 55%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableByteSupplierTest.java
index 4691184e6..734de2cca 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableByteSupplierTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableByteSupplier}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableByteSupplierTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testGetAsByte_returnsValue() throws IOException {
+ final FailableByteSupplier<IOException> supplier = () -> (byte) 5;
+ assertEquals((byte) 5, supplier.getAsByte());
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testGetAsByte_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableByteSupplier<IOException> supplier = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
supplier::getAsByte);
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableCallableTest.java
similarity index 56%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableCallableTest.java
index 4691184e6..b430ca704 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++ b/src/test/java/org/apache/commons/lang3/function/FailableCallableTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableCallable}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableCallableTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testCall_returnsResult() throws IOException {
+ final FailableCallable<String, IOException> callable = () -> "hello";
+ assertEquals("hello", callable.call());
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testCall_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableCallable<String, IOException> callable = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
callable::call);
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleBinaryOperatorTest.java
similarity index 54%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableDoubleBinaryOperatorTest.java
index 4691184e6..347435e51 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleBinaryOperatorTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableDoubleBinaryOperator}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableDoubleBinaryOperatorTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testApplyAsDouble_returnsResult() throws IOException {
+ final FailableDoubleBinaryOperator<IOException> op = (a, b) -> a + b;
+ assertEquals(3.0, op.applyAsDouble(1.0, 2.0));
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testApplyAsDouble_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoubleBinaryOperator<IOException> op = (a, b) -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
op.applyAsDouble(1.0, 2.0));
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableDoubleConsumerTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleConsumerTest.java
new file mode 100644
index 000000000..7fa5be016
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleConsumerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableDoubleConsumer}.
+ */
+class FailableDoubleConsumerTest extends AbstractLangTest {
+
+ @Test
+ void testAccept_invokesConsumer() throws IOException {
+ final AtomicReference<Double> ref = new AtomicReference<>();
+ final FailableDoubleConsumer<IOException> consumer = ref::set;
+ consumer.accept(3.14);
+ assertEquals(3.14, ref.get());
+ }
+
+ @Test
+ void testAccept_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoubleConsumer<IOException> consumer = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
consumer.accept(1.0));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testAndThen_bothInvoked() throws IOException {
+ final AtomicReference<Double> ref1 = new AtomicReference<>();
+ final AtomicReference<Double> ref2 = new AtomicReference<>();
+ final FailableDoubleConsumer<IOException> first = ref1::set;
+ final FailableDoubleConsumer<IOException> second = ref2::set;
+ first.andThen(second).accept(2.5);
+ assertEquals(2.5, ref1.get());
+ assertEquals(2.5, ref2.get());
+ }
+
+ @Test
+ void testAndThen_firstThrows_secondNotInvoked() {
+ final IOException expected = new IOException("first");
+ final AtomicReference<Double> ref = new AtomicReference<>();
+ final FailableDoubleConsumer<IOException> throwing = v -> {
+ throw expected;
+ };
+ final FailableDoubleConsumer<IOException> second = ref::set;
+ final IOException thrown = assertThrows(IOException.class, () ->
throwing.andThen(second).accept(1.0));
+ assertEquals(expected, thrown);
+ assertEquals(null, ref.get());
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableDoubleConsumer<IOException> consumer = v -> {
+ };
+ assertNullPointerException(() -> consumer.andThen(null));
+ }
+
+ @Test
+ void testNop_acceptDoesNothing() throws Throwable {
+ FailableDoubleConsumer.nop().accept(1.0);
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableDoubleConsumer.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleFunctionTest.java
similarity index 50%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableDoubleFunctionTest.java
index 4691184e6..7846273d5 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleFunctionTest.java
@@ -17,33 +17,44 @@
package org.apache.commons.lang3.function;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableDoubleFunction}.
*/
-class FailableSupplierTest extends AbstractLangTest {
+class FailableDoubleFunctionTest extends AbstractLangTest {
@Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
+ void testApply_returnsResult() throws IOException {
+ final FailableDoubleFunction<String, IOException> f = v -> "v=" + v;
+ assertEquals("v=2.5", f.apply(2.5));
}
@Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
+ void testApply_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoubleFunction<String, IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.apply(1.0));
+ assertEquals(expected, thrown);
}
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testNop_applyReturnsNull() throws Throwable {
+ assertNull(FailableDoubleFunction.nop().apply(1.0));
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableDoubleFunction.nop());
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableDoublePredicateTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoublePredicateTest.java
new file mode 100644
index 000000000..4879ab2f3
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoublePredicateTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableDoublePredicate}.
+ */
+class FailableDoublePredicateTest extends AbstractLangTest {
+
+ @Test
+ void testAnd_bothTrue_returnsTrue() throws IOException {
+ final FailableDoublePredicate<IOException> p = v -> true;
+ assertTrue(p.and(v -> true).test(1.0));
+ }
+
+ @Test
+ void testAnd_firstFalse_returnsFalse() throws IOException {
+ final FailableDoublePredicate<IOException> p = v -> false;
+ assertFalse(p.and(v -> true).test(1.0));
+ }
+
+ @Test
+ void testAnd_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableDoublePredicate<IOException> p = v -> true;
+ assertNullPointerException(() -> p.and(null));
+ }
+
+ @Test
+ void testFalsePredicate_returnsFalse() throws Throwable {
+ assertFalse(FailableDoublePredicate.falsePredicate().test(1.0));
+ }
+
+ @Test
+ void testNegate_invertsResult() throws IOException {
+ final FailableDoublePredicate<IOException> p = v -> true;
+ assertFalse(p.negate().test(1.0));
+ assertTrue(p.negate().negate().test(1.0));
+ }
+
+ @Test
+ void testOr_bothFalse_returnsFalse() throws IOException {
+ final FailableDoublePredicate<IOException> p = v -> false;
+ assertFalse(p.or(v -> false).test(1.0));
+ }
+
+ @Test
+ void testOr_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableDoublePredicate<IOException> p = v -> false;
+ assertNullPointerException(() -> p.or(null));
+ }
+
+ @Test
+ void testOr_oneTrue_returnsTrue() throws IOException {
+ final FailableDoublePredicate<IOException> p = v -> false;
+ assertTrue(p.or(v -> true).test(1.0));
+ }
+
+ @Test
+ void testTest_evaluatesCorrectly() throws IOException {
+ final FailableDoublePredicate<IOException> positive = v -> v > 0;
+ assertTrue(positive.test(1.0));
+ assertFalse(positive.test(-1.0));
+ }
+
+ @Test
+ void testTest_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoublePredicate<IOException> p = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
p.test(1.0));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testTruePredicate_returnsTrue() throws Throwable {
+ assertTrue(FailableDoublePredicate.truePredicate().test(1.0));
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleSupplierTest.java
similarity index 55%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableDoubleSupplierTest.java
index 4691184e6..e541cd826 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleSupplierTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableDoubleSupplier}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableDoubleSupplierTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testGetAsDouble_returnsValue() throws IOException {
+ final FailableDoubleSupplier<IOException> supplier = () -> 2.71828;
+ assertEquals(2.71828, supplier.getAsDouble());
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testGetAsDouble_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoubleSupplier<IOException> supplier = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
supplier::getAsDouble);
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableDoubleToIntFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleToIntFunctionTest.java
new file mode 100644
index 000000000..756a61ffc
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleToIntFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableDoubleToIntFunction}.
+ */
+class FailableDoubleToIntFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsInt_returnsResult() throws IOException {
+ final FailableDoubleToIntFunction<IOException> f = v -> (int) v;
+ assertEquals(3, f.applyAsInt(3.9));
+ }
+
+ @Test
+ void testApplyAsInt_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoubleToIntFunction<IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsInt(1.0));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsIntReturnsZero() throws Throwable {
+ assertEquals(0, FailableDoubleToIntFunction.nop().applyAsInt(1.0));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableDoubleToIntFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableDoubleToLongFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleToLongFunctionTest.java
new file mode 100644
index 000000000..88819db85
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleToLongFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableDoubleToLongFunction}.
+ */
+class FailableDoubleToLongFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsLong_returnsResult() throws IOException {
+ final FailableDoubleToLongFunction<IOException> f = v -> (int) v;
+ assertEquals(3, f.applyAsLong(3.9));
+ }
+
+ @Test
+ void testApplyAsLong_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoubleToLongFunction<IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsLong(1.0));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsLongReturnsZero() throws Throwable {
+ assertEquals(0, FailableDoubleToLongFunction.nop().applyAsLong(1.0));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableDoubleToLongFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableDoubleUnaryOperatorTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleUnaryOperatorTest.java
new file mode 100644
index 000000000..0dd06a64d
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableDoubleUnaryOperatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableDoubleUnaryOperator}.
+ */
+class FailableDoubleUnaryOperatorTest extends AbstractLangTest {
+
+ @Test
+ void testAndThen_composesCorrectly() throws IOException {
+ final FailableDoubleUnaryOperator<IOException> times2 = v -> v * 2;
+ final FailableDoubleUnaryOperator<IOException> plus1 = v -> v + 1;
+ assertEquals(7.0, times2.andThen(plus1).applyAsDouble(3.0));
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableDoubleUnaryOperator<IOException> op = v -> v;
+ assertNullPointerException(() -> op.andThen(null));
+ }
+
+ @Test
+ void testApplyAsDouble_returnsResult() throws IOException {
+ final FailableDoubleUnaryOperator<IOException> op = v -> v * 2;
+ assertEquals(6.0, op.applyAsDouble(3.0));
+ }
+
+ @Test
+ void testApplyAsDouble_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableDoubleUnaryOperator<IOException> op = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
op.applyAsDouble(1.0));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testCompose_composesCorrectly() throws IOException {
+ final FailableDoubleUnaryOperator<IOException> times2 = v -> v * 2;
+ final FailableDoubleUnaryOperator<IOException> plus1 = v -> v + 1;
+ assertEquals(8.0, times2.compose(plus1).applyAsDouble(3.0));
+ }
+
+ @Test
+ void testCompose_nullBefore_throwsNullPointerException() throws Throwable {
+ final FailableDoubleUnaryOperator<IOException> op = v -> v;
+ assertNullPointerException(() -> op.compose(null));
+ }
+
+ @Test
+ void testIdentity_returnsInput() throws IOException {
+ assertEquals(3.14,
FailableDoubleUnaryOperator.<IOException>identity().applyAsDouble(3.14));
+ }
+
+ @Test
+ void testNop_applyAsDoubleReturnsZero() throws Throwable {
+ assertEquals(0d, FailableDoubleUnaryOperator.nop().applyAsDouble(5.0));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableDoubleUnaryOperator.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableFunctionTest.java
new file mode 100644
index 000000000..b3b518098
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/function/FailableFunctionTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableFunction}.
+ */
+class FailableFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testAndThen_composesCorrectly() throws IOException {
+ final FailableFunction<String, Integer, IOException> length =
String::length;
+ final FailableFunction<Integer, String, IOException> toStr = i ->
"len=" + i;
+ assertEquals("len=5", length.andThen(toStr).apply("hello"));
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableFunction<String, String, IOException> f = s -> s;
+ assertNullPointerException(() -> f.andThen(null));
+ }
+
+ @Test
+ void testApply_returnsResult() throws IOException {
+ final FailableFunction<String, Integer, IOException> f =
String::length;
+ assertEquals(5, f.apply("hello"));
+ }
+
+ @Test
+ void testApply_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableFunction<String, String, IOException> f = s -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.apply("x"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testCompose_composesCorrectly() throws IOException {
+ final FailableFunction<String, String, IOException> upper =
String::toUpperCase;
+ final FailableFunction<String, String, IOException> trim =
String::trim;
+ assertEquals("HELLO", upper.compose(trim).apply(" hello "));
+ }
+
+ @Test
+ void testCompose_nullBefore_throwsNullPointerException() throws Throwable {
+ final FailableFunction<String, String, IOException> f = s -> s;
+ assertNullPointerException(() -> f.compose(null));
+ }
+
+ @Test
+ void testFunction_returnsArgument() throws IOException {
+ final FailableFunction<String, String, IOException> f =
String::toUpperCase;
+ final FailableFunction<String, String, IOException> wrapped =
FailableFunction.function(f);
+ assertEquals("HELLO", wrapped.apply("hello"));
+ }
+
+ @Test
+ void testIdentity_returnsInput() throws IOException {
+ final String input = "hello";
+ assertSame(input, FailableFunction.<String,
IOException>identity().apply(input));
+ }
+
+ @Test
+ void testNop_applyReturnsNull() throws Throwable {
+ assertNull(FailableFunction.nop().apply("x"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntBinaryOperatorTest.java
similarity index 55%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableIntBinaryOperatorTest.java
index 4691184e6..d8f4a0823 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntBinaryOperatorTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableIntBinaryOperator}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableIntBinaryOperatorTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testApplyAsInt_returnsResult() throws IOException {
+ final FailableIntBinaryOperator<IOException> op = (a, b) -> a + b;
+ assertEquals(7, op.applyAsInt(3, 4));
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testApplyAsInt_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntBinaryOperator<IOException> op = (a, b) -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
op.applyAsInt(1, 2));
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableIntConsumerTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntConsumerTest.java
new file mode 100644
index 000000000..fa174e10b
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntConsumerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableIntConsumer}.
+ */
+class FailableIntConsumerTest extends AbstractLangTest {
+
+ @Test
+ void testAccept_invokesConsumer() throws IOException {
+ final AtomicInteger ref = new AtomicInteger();
+ final FailableIntConsumer<IOException> consumer = ref::set;
+ consumer.accept(42);
+ assertEquals(42, ref.get());
+ }
+
+ @Test
+ void testAccept_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntConsumer<IOException> consumer = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
consumer.accept(1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testAndThen_bothInvoked() throws IOException {
+ final AtomicInteger ref1 = new AtomicInteger();
+ final AtomicInteger ref2 = new AtomicInteger();
+ final FailableIntConsumer<IOException> first = ref1::set;
+ final FailableIntConsumer<IOException> second = ref2::set;
+ first.andThen(second).accept(9);
+ assertEquals(9, ref1.get());
+ assertEquals(9, ref2.get());
+ }
+
+ @Test
+ void testAndThen_firstThrows_secondNotInvoked() {
+ final IOException expected = new IOException("first");
+ final AtomicInteger ref = new AtomicInteger(-1);
+ final FailableIntConsumer<IOException> throwing = v -> {
+ throw expected;
+ };
+ final FailableIntConsumer<IOException> second = ref::set;
+ final IOException thrown = assertThrows(IOException.class, () ->
throwing.andThen(second).accept(1));
+ assertEquals(expected, thrown);
+ assertEquals(-1, ref.get());
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableIntConsumer<IOException> consumer = v -> {
+ };
+ assertNullPointerException(() -> consumer.andThen(null));
+ }
+
+ @Test
+ void testNop_acceptDoesNothing() throws Throwable {
+ FailableIntConsumer.nop().accept(1);
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableIntConsumer.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntFunctionTest.java
similarity index 51%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableIntFunctionTest.java
index 4691184e6..f84c5ed60 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntFunctionTest.java
@@ -17,33 +17,44 @@
package org.apache.commons.lang3.function;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableIntFunction}.
*/
-class FailableSupplierTest extends AbstractLangTest {
+class FailableIntFunctionTest extends AbstractLangTest {
@Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
+ void testApply_returnsResult() throws IOException {
+ final FailableIntFunction<String, IOException> f = v -> "v=" + v;
+ assertEquals("v=5", f.apply(5));
}
@Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
+ void testApply_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntFunction<String, IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.apply(1));
+ assertEquals(expected, thrown);
}
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testNop_applyReturnsNull() throws Throwable {
+ assertNull(FailableIntFunction.nop().apply(1));
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableIntFunction.nop());
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableIntPredicateTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntPredicateTest.java
new file mode 100644
index 000000000..a2c0c66fb
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntPredicateTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableIntPredicate}.
+ */
+class FailableIntPredicateTest extends AbstractLangTest {
+
+ @Test
+ void testAnd_bothTrue_returnsTrue() throws IOException {
+ final FailableIntPredicate<IOException> p = v -> true;
+ assertTrue(p.and(v -> true).test(1));
+ }
+
+ @Test
+ void testAnd_firstFalse_returnsFalse() throws IOException {
+ final FailableIntPredicate<IOException> p = v -> false;
+ assertFalse(p.and(v -> true).test(1));
+ }
+
+ @Test
+ void testAnd_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableIntPredicate<IOException> p = v -> true;
+ assertNullPointerException(() -> p.and(null));
+ }
+
+ @Test
+ void testFalsePredicate_returnsFalse() throws Throwable {
+ assertFalse(FailableIntPredicate.falsePredicate().test(1));
+ }
+
+ @Test
+ void testNegate_invertsResult() throws IOException {
+ final FailableIntPredicate<IOException> p = v -> true;
+ assertFalse(p.negate().test(1));
+ assertTrue(p.negate().negate().test(1));
+ }
+
+ @Test
+ void testOr_bothFalse_returnsFalse() throws IOException {
+ final FailableIntPredicate<IOException> p = v -> false;
+ assertFalse(p.or(v -> false).test(1));
+ }
+
+ @Test
+ void testOr_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableIntPredicate<IOException> p = v -> false;
+ assertNullPointerException(() -> p.or(null));
+ }
+
+ @Test
+ void testOr_oneTrue_returnsTrue() throws IOException {
+ final FailableIntPredicate<IOException> p = v -> false;
+ assertTrue(p.or(v -> true).test(1));
+ }
+
+ @Test
+ void testTest_evaluatesCorrectly() throws IOException {
+ final FailableIntPredicate<IOException> positive = v -> v > 0;
+ assertTrue(positive.test(1));
+ assertFalse(positive.test(-1));
+ }
+
+ @Test
+ void testTest_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntPredicate<IOException> p = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
p.test(1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testTruePredicate_returnsTrue() throws Throwable {
+ assertTrue(FailableIntPredicate.truePredicate().test(1));
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntSupplierTest.java
similarity index 56%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableIntSupplierTest.java
index 4691184e6..b40d43338 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntSupplierTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableIntSupplier}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableIntSupplierTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testGetAsInt_returnsValue() throws IOException {
+ final FailableIntSupplier<IOException> supplier = () -> 42;
+ assertEquals(42, supplier.getAsInt());
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testGetAsInt_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntSupplier<IOException> supplier = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
supplier::getAsInt);
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableIntToDoubleFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntToDoubleFunctionTest.java
new file mode 100644
index 000000000..460d6a50a
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntToDoubleFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableIntToDoubleFunction}.
+ */
+class FailableIntToDoubleFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsDouble_returnsResult() throws IOException {
+ final FailableIntToDoubleFunction<IOException> f = v -> v * 1.5;
+ assertEquals(4.5, f.applyAsDouble(3));
+ }
+
+ @Test
+ void testApplyAsDouble_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntToDoubleFunction<IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsDouble(1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsDoubleReturnsZero() throws Throwable {
+ assertEquals(0d, FailableIntToDoubleFunction.nop().applyAsDouble(1));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableIntToDoubleFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableIntToFloatFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntToFloatFunctionTest.java
new file mode 100644
index 000000000..2d923964a
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntToFloatFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableIntToFloatFunction}.
+ */
+class FailableIntToFloatFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsFloat_returnsResult() throws IOException {
+ final FailableIntToFloatFunction<IOException> f = v -> v * 0.5f;
+ assertEquals(1.5f, f.applyAsFloat(3));
+ }
+
+ @Test
+ void testApplyAsFloat_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntToFloatFunction<IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsFloat(1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsFloatReturnsZero() throws Throwable {
+ assertEquals(0f, FailableIntToFloatFunction.nop().applyAsFloat(1));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableIntToFloatFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableIntToLongFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntToLongFunctionTest.java
new file mode 100644
index 000000000..f649b221a
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntToLongFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableIntToLongFunction}.
+ */
+class FailableIntToLongFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsLong_returnsResult() throws IOException {
+ final FailableIntToLongFunction<IOException> f = v -> (long) v *
1_000_000L;
+ assertEquals(3_000_000L, f.applyAsLong(3));
+ }
+
+ @Test
+ void testApplyAsLong_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntToLongFunction<IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsLong(1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsLongReturnsZero() throws Throwable {
+ assertEquals(0L, FailableIntToLongFunction.nop().applyAsLong(1));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableIntToLongFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableIntUnaryOperatorTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableIntUnaryOperatorTest.java
new file mode 100644
index 000000000..6b8442173
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableIntUnaryOperatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableIntUnaryOperator}.
+ */
+class FailableIntUnaryOperatorTest extends AbstractLangTest {
+
+ @Test
+ void testAndThen_composesCorrectly() throws IOException {
+ final FailableIntUnaryOperator<IOException> times2 = v -> v * 2;
+ final FailableIntUnaryOperator<IOException> plus1 = v -> v + 1;
+ assertEquals(7, times2.andThen(plus1).applyAsInt(3));
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableIntUnaryOperator<IOException> op = v -> v;
+ assertNullPointerException(() -> op.andThen(null));
+ }
+
+ @Test
+ void testApplyAsInt_returnsResult() throws IOException {
+ final FailableIntUnaryOperator<IOException> op = v -> v * 3;
+ assertEquals(15, op.applyAsInt(5));
+ }
+
+ @Test
+ void testApplyAsInt_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableIntUnaryOperator<IOException> op = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
op.applyAsInt(1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testCompose_composesCorrectly() throws IOException {
+ final FailableIntUnaryOperator<IOException> times2 = v -> v * 2;
+ final FailableIntUnaryOperator<IOException> plus1 = v -> v + 1;
+ assertEquals(8, times2.compose(plus1).applyAsInt(3));
+ }
+
+ @Test
+ void testCompose_nullBefore_throwsNullPointerException() throws Throwable {
+ final FailableIntUnaryOperator<IOException> op = v -> v;
+ assertNullPointerException(() -> op.compose(null));
+ }
+
+ @Test
+ void testIdentity_returnsInput() throws IOException {
+ assertEquals(7,
FailableIntUnaryOperator.<IOException>identity().applyAsInt(7));
+ }
+
+ @Test
+ void testNop_applyAsIntReturnsZero() throws Throwable {
+ assertEquals(0, FailableIntUnaryOperator.nop().applyAsInt(5));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableIntUnaryOperator.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongBinaryOperatorTest.java
similarity index 55%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableLongBinaryOperatorTest.java
index 4691184e6..187aaaae3 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongBinaryOperatorTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableLongBinaryOperator}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableLongBinaryOperatorTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testApplyAsLong_returnsResult() throws IOException {
+ final FailableLongBinaryOperator<IOException> op = (a, b) -> a + b;
+ assertEquals(7L, op.applyAsLong(3L, 4L));
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testApplyAsLong_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongBinaryOperator<IOException> op = (a, b) -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
op.applyAsLong(1L, 2L));
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableLongConsumerTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongConsumerTest.java
new file mode 100644
index 000000000..b2e7a7aa4
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongConsumerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableLongConsumer}.
+ */
+class FailableLongConsumerTest extends AbstractLangTest {
+
+ @Test
+ void testAccept_invokesConsumer() throws IOException {
+ final AtomicLong ref = new AtomicLong();
+ final FailableLongConsumer<IOException> consumer = ref::set;
+ consumer.accept(100L);
+ assertEquals(100L, ref.get());
+ }
+
+ @Test
+ void testAccept_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongConsumer<IOException> consumer = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
consumer.accept(1L));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testAndThen_bothInvoked() throws IOException {
+ final AtomicLong ref1 = new AtomicLong();
+ final AtomicLong ref2 = new AtomicLong();
+ final FailableLongConsumer<IOException> first = ref1::set;
+ final FailableLongConsumer<IOException> second = ref2::set;
+ first.andThen(second).accept(99L);
+ assertEquals(99L, ref1.get());
+ assertEquals(99L, ref2.get());
+ }
+
+ @Test
+ void testAndThen_firstThrows_secondNotInvoked() {
+ final IOException expected = new IOException("first");
+ final AtomicLong ref = new AtomicLong(-1L);
+ final FailableLongConsumer<IOException> throwing = v -> {
+ throw expected;
+ };
+ final FailableLongConsumer<IOException> second = ref::set;
+ final IOException thrown = assertThrows(IOException.class, () ->
throwing.andThen(second).accept(1L));
+ assertEquals(expected, thrown);
+ assertEquals(-1L, ref.get());
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableLongConsumer<IOException> consumer = v -> {
+ };
+ assertNullPointerException(() -> consumer.andThen(null));
+ }
+
+ @Test
+ void testNop_acceptDoesNothing() throws Throwable {
+ FailableLongConsumer.nop().accept(1L);
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableLongConsumer.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongFunctionTest.java
similarity index 51%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableLongFunctionTest.java
index 4691184e6..00b131598 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongFunctionTest.java
@@ -17,33 +17,44 @@
package org.apache.commons.lang3.function;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableLongFunction}.
*/
-class FailableSupplierTest extends AbstractLangTest {
+class FailableLongFunctionTest extends AbstractLangTest {
@Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
+ void testApply_returnsResult() throws IOException {
+ final FailableLongFunction<String, IOException> f = v -> "v=" + v;
+ assertEquals("v=5", f.apply(5L));
}
@Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
+ void testApply_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongFunction<String, IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.apply(1L));
+ assertEquals(expected, thrown);
}
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testNop_applyReturnsNull() throws Throwable {
+ assertNull(FailableLongFunction.nop().apply(1L));
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableLongFunction.nop());
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableLongPredicateTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongPredicateTest.java
new file mode 100644
index 000000000..8d9746bf4
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongPredicateTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableLongPredicate}.
+ */
+class FailableLongPredicateTest extends AbstractLangTest {
+
+ @Test
+ void testAnd_bothTrue_returnsTrue() throws IOException {
+ final FailableLongPredicate<IOException> p = v -> true;
+ assertTrue(p.and(v -> true).test(1L));
+ }
+
+ @Test
+ void testAnd_firstFalse_returnsFalse() throws IOException {
+ final FailableLongPredicate<IOException> p = v -> false;
+ assertFalse(p.and(v -> true).test(1L));
+ }
+
+ @Test
+ void testAnd_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableLongPredicate<IOException> p = v -> true;
+ assertNullPointerException(() -> p.and(null));
+ }
+
+ @Test
+ void testFalsePredicate_returnsFalse() throws Throwable {
+ assertFalse(FailableLongPredicate.falsePredicate().test(1L));
+ }
+
+ @Test
+ void testNegate_invertsResult() throws IOException {
+ final FailableLongPredicate<IOException> p = v -> true;
+ assertFalse(p.negate().test(1L));
+ assertTrue(p.negate().negate().test(1L));
+ }
+
+ @Test
+ void testOr_bothFalse_returnsFalse() throws IOException {
+ final FailableLongPredicate<IOException> p = v -> false;
+ assertFalse(p.or(v -> false).test(1L));
+ }
+
+ @Test
+ void testOr_nullOther_throwsNullPointerException() throws Throwable {
+ final FailableLongPredicate<IOException> p = v -> false;
+ assertNullPointerException(() -> p.or(null));
+ }
+
+ @Test
+ void testOr_oneTrue_returnsTrue() throws IOException {
+ final FailableLongPredicate<IOException> p = v -> false;
+ assertTrue(p.or(v -> true).test(1L));
+ }
+
+ @Test
+ void testTest_evaluatesCorrectly() throws IOException {
+ final FailableLongPredicate<IOException> positive = v -> v > 0;
+ assertTrue(positive.test(1L));
+ assertFalse(positive.test(-1L));
+ }
+
+ @Test
+ void testTest_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongPredicate<IOException> p = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
p.test(1L));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testTruePredicate_returnsTrue() throws Throwable {
+ assertTrue(FailableLongPredicate.truePredicate().test(1L));
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongSupplierTest.java
similarity index 56%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableLongSupplierTest.java
index 4691184e6..c78de2027 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongSupplierTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableLongSupplier}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableLongSupplierTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testGetAsLong_returnsValue() throws IOException {
+ final FailableLongSupplier<IOException> supplier = () -> 123L;
+ assertEquals(123L, supplier.getAsLong());
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testGetAsLong_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongSupplier<IOException> supplier = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
supplier::getAsLong);
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableLongToDoubleFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongToDoubleFunctionTest.java
new file mode 100644
index 000000000..e47ddd6b8
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongToDoubleFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableLongToDoubleFunction}.
+ */
+class FailableLongToDoubleFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsDouble_returnsResult() throws IOException {
+ final FailableLongToDoubleFunction<IOException> f = v -> v * 0.5;
+ assertEquals(1.5, f.applyAsDouble(3L));
+ }
+
+ @Test
+ void testApplyAsDouble_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongToDoubleFunction<IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsDouble(1L));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsDoubleReturnsZero() throws Throwable {
+ assertEquals(0d, FailableLongToDoubleFunction.nop().applyAsDouble(1L));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableLongToDoubleFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableLongToIntFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongToIntFunctionTest.java
new file mode 100644
index 000000000..4bd3fa880
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongToIntFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableLongToIntFunction}.
+ */
+class FailableLongToIntFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsInt_returnsResult() throws IOException {
+ final FailableLongToIntFunction<IOException> f = v -> (int) (v % 100);
+ assertEquals(42, f.applyAsInt(142L));
+ }
+
+ @Test
+ void testApplyAsInt_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongToIntFunction<IOException> f = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsInt(1L));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsIntReturnsZero() throws Throwable {
+ assertEquals(0, FailableLongToIntFunction.nop().applyAsInt(1L));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableLongToIntFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableLongUnaryOperatorTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableLongUnaryOperatorTest.java
new file mode 100644
index 000000000..a83b4da3e
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableLongUnaryOperatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableLongUnaryOperator}.
+ */
+class FailableLongUnaryOperatorTest extends AbstractLangTest {
+
+ @Test
+ void testAndThen_composesCorrectly() throws IOException {
+ final FailableLongUnaryOperator<IOException> times2 = v -> v * 2;
+ final FailableLongUnaryOperator<IOException> plus1 = v -> v + 1;
+ assertEquals(7L, times2.andThen(plus1).applyAsLong(3L));
+ }
+
+ @Test
+ void testAndThen_nullAfter_throwsNullPointerException() throws Throwable {
+ final FailableLongUnaryOperator<IOException> op = v -> v;
+ assertNullPointerException(() -> op.andThen(null));
+ }
+
+ @Test
+ void testApplyAsLong_returnsResult() throws IOException {
+ final FailableLongUnaryOperator<IOException> op = v -> v * 2;
+ assertEquals(10L, op.applyAsLong(5L));
+ }
+
+ @Test
+ void testApplyAsLong_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableLongUnaryOperator<IOException> op = v -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
op.applyAsLong(1L));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testCompose_composesCorrectly() throws IOException {
+ final FailableLongUnaryOperator<IOException> times2 = v -> v * 2;
+ final FailableLongUnaryOperator<IOException> plus1 = v -> v + 1;
+ assertEquals(8L, times2.compose(plus1).applyAsLong(3L));
+ }
+
+ @Test
+ void testCompose_nullBefore_throwsNullPointerException() throws Throwable {
+ final FailableLongUnaryOperator<IOException> op = v -> v;
+ assertNullPointerException(() -> op.compose(null));
+ }
+
+ @Test
+ void testIdentity_returnsInput() throws IOException {
+ assertEquals(7L,
FailableLongUnaryOperator.<IOException>identity().applyAsLong(7L));
+ }
+
+ @Test
+ void testNop_applyAsLongReturnsZero() throws Throwable {
+ assertEquals(0L, FailableLongUnaryOperator.nop().applyAsLong(5L));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableLongUnaryOperator.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableObjDoubleConsumerTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableObjDoubleConsumerTest.java
new file mode 100644
index 000000000..7732a22ed
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableObjDoubleConsumerTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableObjDoubleConsumer}.
+ */
+class FailableObjDoubleConsumerTest extends AbstractLangTest {
+
+ @Test
+ void testAccept_invokesConsumer() throws IOException {
+ final AtomicReference<String> objRef = new AtomicReference<>();
+ final AtomicReference<Double> valRef = new AtomicReference<>();
+ final FailableObjDoubleConsumer<String, IOException> consumer = (o, v)
-> {
+ objRef.set(o);
+ valRef.set(v);
+ };
+ consumer.accept("hello", 3.14);
+ assertEquals("hello", objRef.get());
+ assertEquals(3.14, valRef.get());
+ }
+
+ @Test
+ void testAccept_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableObjDoubleConsumer<String, IOException> consumer = (o, v)
-> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
consumer.accept("x", 1.0));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_acceptDoesNothing() throws Throwable {
+ FailableObjDoubleConsumer.nop().accept("x", 1.0);
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableObjDoubleConsumer.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableObjIntConsumerTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableObjIntConsumerTest.java
new file mode 100644
index 000000000..0bf664c34
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableObjIntConsumerTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableObjIntConsumer}.
+ */
+class FailableObjIntConsumerTest extends AbstractLangTest {
+
+ @Test
+ void testAccept_invokesConsumer() throws IOException {
+ final AtomicReference<String> objRef = new AtomicReference<>();
+ final AtomicInteger valRef = new AtomicInteger();
+ final FailableObjIntConsumer<String, IOException> consumer = (o, v) ->
{
+ objRef.set(o);
+ valRef.set(v);
+ };
+ consumer.accept("hello", 42);
+ assertEquals("hello", objRef.get());
+ assertEquals(42, valRef.get());
+ }
+
+ @Test
+ void testAccept_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableObjIntConsumer<String, IOException> consumer = (o, v) ->
{
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
consumer.accept("x", 1));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_acceptDoesNothing() throws Throwable {
+ FailableObjIntConsumer.nop().accept("x", 1);
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableObjIntConsumer.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableObjLongConsumerTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableObjLongConsumerTest.java
new file mode 100644
index 000000000..245f72f0a
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableObjLongConsumerTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableObjLongConsumer}.
+ */
+class FailableObjLongConsumerTest extends AbstractLangTest {
+
+ @Test
+ void testAccept_invokesConsumer() throws IOException {
+ final AtomicReference<String> objRef = new AtomicReference<>();
+ final AtomicLong valRef = new AtomicLong();
+ final FailableObjLongConsumer<String, IOException> consumer = (o, v)
-> {
+ objRef.set(o);
+ valRef.set(v);
+ };
+ consumer.accept("hello", 99L);
+ assertEquals("hello", objRef.get());
+ assertEquals(99L, valRef.get());
+ }
+
+ @Test
+ void testAccept_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableObjLongConsumer<String, IOException> consumer = (o, v)
-> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
consumer.accept("x", 1L));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_acceptDoesNothing() throws Throwable {
+ FailableObjLongConsumer.nop().accept("x", 1L);
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableObjLongConsumer.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailablePredicateTest.java
b/src/test/java/org/apache/commons/lang3/function/FailablePredicateTest.java
new file mode 100644
index 000000000..e3fb46c1c
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/function/FailablePredicateTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static
org.apache.commons.lang3.LangAssertions.assertNullPointerException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailablePredicate}.
+ */
+class FailablePredicateTest extends AbstractLangTest {
+
+ @Test
+ void testAnd_bothTrue_returnsTrue() throws IOException {
+ final FailablePredicate<String, IOException> p = s -> true;
+ assertTrue(p.and(s -> true).test("x"));
+ }
+
+ @Test
+ void testAnd_firstFalse_returnsFalse() throws IOException {
+ final FailablePredicate<String, IOException> p = s -> false;
+ assertFalse(p.and(s -> true).test("x"));
+ }
+
+ @Test
+ void testAnd_nullOther_throwsNullPointerException() throws Throwable {
+ final FailablePredicate<String, IOException> p = s -> true;
+ assertNullPointerException(() -> p.and(null));
+ }
+
+ @Test
+ void testFalsePredicate_returnsFalse() throws Throwable {
+ assertFalse(FailablePredicate.falsePredicate().test("anything"));
+ }
+
+ @Test
+ void testNegate_invertsResult() throws IOException {
+ final FailablePredicate<String, IOException> p = s -> true;
+ assertFalse(p.negate().test("x"));
+ assertTrue(p.negate().negate().test("x"));
+ }
+
+ @Test
+ void testOr_bothFalse_returnsFalse() throws IOException {
+ final FailablePredicate<String, IOException> p = s -> false;
+ assertFalse(p.or(s -> false).test("x"));
+ }
+
+ @Test
+ void testOr_nullOther_throwsNullPointerException() throws Throwable {
+ final FailablePredicate<String, IOException> p = s -> false;
+ assertNullPointerException(() -> p.or(null));
+ }
+
+ @Test
+ void testOr_oneTrue_returnsTrue() throws IOException {
+ final FailablePredicate<String, IOException> p = s -> false;
+ assertTrue(p.or(s -> true).test("x"));
+ }
+
+ @Test
+ void testTest_evaluatesCorrectly() throws IOException {
+ final FailablePredicate<String, IOException> nonEmpty = s ->
!s.isEmpty();
+ assertTrue(nonEmpty.test("hello"));
+ assertFalse(nonEmpty.test(""));
+ }
+
+ @Test
+ void testTest_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailablePredicate<String, IOException> p = s -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
p.test("x"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testTruePredicate_returnsTrue() throws Throwable {
+ assertTrue(FailablePredicate.truePredicate().test("anything"));
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableRunnableTest.java
similarity index 51%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableRunnableTest.java
index 4691184e6..fc0f8195c 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++ b/src/test/java/org/apache/commons/lang3/function/FailableRunnableTest.java
@@ -17,33 +17,36 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableRunnable}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableRunnableTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testRun_executesBody() throws IOException {
+ final AtomicBoolean ran = new AtomicBoolean();
+ final FailableRunnable<IOException> runnable = () -> ran.set(true);
+ runnable.run();
+ assertTrue(ran.get());
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testRun_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableRunnable<IOException> runnable = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
runnable::run);
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableShortSupplierTest.java
similarity index 55%
copy from
src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
copy to
src/test/java/org/apache/commons/lang3/function/FailableShortSupplierTest.java
index 4691184e6..fa99ebeaf 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++
b/src/test/java/org/apache/commons/lang3/function/FailableShortSupplierTest.java
@@ -17,33 +17,32 @@
package org.apache.commons.lang3.function;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
/**
- * Tests {@link FailableSupplier}.
+ * Tests {@link FailableShortSupplier}.
*/
-class FailableSupplierTest extends AbstractLangTest {
-
- @Test
- void testNULL() throws Throwable {
- assertNull(FailableSupplier.NUL.get());
- }
-
- @Test
- void testNullSupplierDefaultException() throws Exception {
- assertNull(FailableSupplier.nul().get());
- }
+class FailableShortSupplierTest extends AbstractLangTest {
@Test
- void testNullSupplierException() throws Exception {
- assertNull(FailableSupplier.<Object, Exception>nul().get());
+ void testGetAsShort_returnsValue() throws IOException {
+ final FailableShortSupplier<IOException> supplier = () -> (short) 7;
+ assertEquals((short) 7, supplier.getAsShort());
}
@Test
- void testNullSupplierRuntimeException() {
- assertNull(FailableSupplier.<Object, RuntimeException>nul().get());
+ void testGetAsShort_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableShortSupplier<IOException> supplier = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
supplier::getAsShort);
+ assertEquals(expected, thrown);
}
}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
index 4691184e6..157e0cad0 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
+++ b/src/test/java/org/apache/commons/lang3/function/FailableSupplierTest.java
@@ -17,7 +17,11 @@
package org.apache.commons.lang3.function;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
import org.apache.commons.lang3.AbstractLangTest;
import org.junit.jupiter.api.Test;
@@ -27,6 +31,22 @@
*/
class FailableSupplierTest extends AbstractLangTest {
+ @Test
+ void testGet_returnsValue() throws IOException {
+ final FailableSupplier<String, IOException> supplier = () -> "hello";
+ assertEquals("hello", supplier.get());
+ }
+
+ @Test
+ void testGet_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableSupplier<String, IOException> supplier = () -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class,
supplier::get);
+ assertEquals(expected, thrown);
+ }
+
@Test
void testNULL() throws Throwable {
assertNull(FailableSupplier.NUL.get());
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableToBooleanFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableToBooleanFunctionTest.java
new file mode 100644
index 000000000..2e4986c26
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableToBooleanFunctionTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableToBooleanFunction}.
+ */
+class FailableToBooleanFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsBoolean_returnsTrue() throws IOException {
+ final FailableToBooleanFunction<String, IOException> f = s ->
!s.isEmpty();
+ assertTrue(f.applyAsBoolean("hello"));
+ assertFalse(f.applyAsBoolean(""));
+ }
+
+ @Test
+ void testApplyAsBoolean_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableToBooleanFunction<String, IOException> f = s -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsBoolean("x"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsBooleanReturnsFalse() throws Throwable {
+ assertFalse(FailableToBooleanFunction.nop().applyAsBoolean("x"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableToBooleanFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableToDoubleBiFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableToDoubleBiFunctionTest.java
new file mode 100644
index 000000000..350b2a080
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableToDoubleBiFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableToDoubleBiFunction}.
+ */
+class FailableToDoubleBiFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsDouble_returnsResult() throws IOException {
+ final FailableToDoubleBiFunction<String, String, IOException> f = (a,
b) -> a.length() + b.length();
+ assertEquals(5.0, f.applyAsDouble("ab", "abc"));
+ }
+
+ @Test
+ void testApplyAsDouble_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableToDoubleBiFunction<String, String, IOException> f = (a,
b) -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsDouble("a", "b"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsDoubleReturnsZero() throws Throwable {
+ assertEquals(0d, FailableToDoubleBiFunction.nop().applyAsDouble("a",
"b"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableToDoubleBiFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableToDoubleFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableToDoubleFunctionTest.java
new file mode 100644
index 000000000..288951046
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableToDoubleFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableToDoubleFunction}.
+ */
+class FailableToDoubleFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsDouble_returnsResult() throws IOException {
+ final FailableToDoubleFunction<String, IOException> f = s ->
s.length() * 1.5;
+ assertEquals(7.5, f.applyAsDouble("hello"));
+ }
+
+ @Test
+ void testApplyAsDouble_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableToDoubleFunction<String, IOException> f = s -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsDouble("x"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsDoubleReturnsZero() throws Throwable {
+ assertEquals(0d, FailableToDoubleFunction.nop().applyAsDouble("x"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableToDoubleFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableToIntBiFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableToIntBiFunctionTest.java
new file mode 100644
index 000000000..f3bb25c71
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableToIntBiFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableToIntBiFunction}.
+ */
+class FailableToIntBiFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsInt_returnsResult() throws IOException {
+ final FailableToIntBiFunction<String, String, IOException> f = (a, b)
-> a.length() + b.length();
+ assertEquals(5, f.applyAsInt("ab", "abc"));
+ }
+
+ @Test
+ void testApplyAsInt_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableToIntBiFunction<String, String, IOException> f = (a, b)
-> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsInt("a", "b"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsIntReturnsZero() throws Throwable {
+ assertEquals(0, FailableToIntBiFunction.nop().applyAsInt("a", "b"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableToIntBiFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableToIntFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableToIntFunctionTest.java
new file mode 100644
index 000000000..e21b6c004
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableToIntFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableToIntFunction}.
+ */
+class FailableToIntFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsInt_returnsResult() throws IOException {
+ final FailableToIntFunction<String, IOException> f = String::length;
+ assertEquals(5, f.applyAsInt("hello"));
+ }
+
+ @Test
+ void testApplyAsInt_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableToIntFunction<String, IOException> f = s -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsInt("x"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsIntReturnsZero() throws Throwable {
+ assertEquals(0, FailableToIntFunction.nop().applyAsInt("x"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableToIntFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableToLongBiFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableToLongBiFunctionTest.java
new file mode 100644
index 000000000..13c3f9f3f
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableToLongBiFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableToLongBiFunction}.
+ */
+class FailableToLongBiFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsLong_returnsResult() throws IOException {
+ final FailableToLongBiFunction<String, String, IOException> f = (a, b)
-> a.length() + b.length();
+ assertEquals(5L, f.applyAsLong("ab", "abc"));
+ }
+
+ @Test
+ void testApplyAsLong_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableToLongBiFunction<String, String, IOException> f = (a, b)
-> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsLong("a", "b"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsLongReturnsZero() throws Throwable {
+ assertEquals(0L, FailableToLongBiFunction.nop().applyAsLong("a", "b"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableToLongBiFunction.nop());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/lang3/function/FailableToLongFunctionTest.java
b/src/test/java/org/apache/commons/lang3/function/FailableToLongFunctionTest.java
new file mode 100644
index 000000000..a35e73059
--- /dev/null
+++
b/src/test/java/org/apache/commons/lang3/function/FailableToLongFunctionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.AbstractLangTest;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link FailableToLongFunction}.
+ */
+class FailableToLongFunctionTest extends AbstractLangTest {
+
+ @Test
+ void testApplyAsLong_returnsResult() throws IOException {
+ final FailableToLongFunction<String, IOException> f = s -> (long)
s.length() * 10;
+ assertEquals(50L, f.applyAsLong("hello"));
+ }
+
+ @Test
+ void testApplyAsLong_throwsException() {
+ final IOException expected = new IOException("fail");
+ final FailableToLongFunction<String, IOException> f = s -> {
+ throw expected;
+ };
+ final IOException thrown = assertThrows(IOException.class, () ->
f.applyAsLong("x"));
+ assertEquals(expected, thrown);
+ }
+
+ @Test
+ void testNop_applyAsLongReturnsZero() throws Throwable {
+ assertEquals(0L, FailableToLongFunction.nop().applyAsLong("x"));
+ }
+
+ @Test
+ void testNop_returnsNonNull() {
+ assertNotNull(FailableToLongFunction.nop());
+ }
+}