1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * https://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */1718package org.apache.commons.lang3.function;
1920importstatic org.apache.commons.lang3.LangAssertions.assertNullPointerException;
21importstatic org.junit.jupiter.api.Assertions.assertEquals;
22importstatic org.junit.jupiter.api.Assertions.assertFalse;
23importstatic org.junit.jupiter.api.Assertions.assertThrows;
2425import java.lang.reflect.Method;
26import java.util.function.BiFunction;
2728import org.apache.commons.lang3.exception.CustomUncheckedException;
29import org.junit.jupiter.api.Test;
3031/**32 * Tests {@link MethodInvokers#asBiFunction(Method)}.33 */34classMethodInvokersBiFunctionTestextendsMethodFixtures {
3536 @Test
37void testApply1Arg() throws NoSuchMethodException, SecurityException {
38final BiFunction<MethodFixtures, String, String> func = MethodInvokers.asBiFunction(getMethodForGetString1Arg());
39 assertEquals(INSTANCE.getString1Arg("A"), func.apply(INSTANCE, "A"));
40 }
4142 @Test
43void testApply1ArgThrowsUnchecked() throws NoSuchMethodException, SecurityException {
44final BiFunction<MethodFixtures, String, String> func = MethodInvokers.asBiFunction(getMethodForGetString1ArgThrowsUnchecked());
45 assertThrows(CustomUncheckedException.class, () -> func.apply(INSTANCE, "A"));
46 }
4748 @Test
49void testConstructorForNull() throws SecurityException {
50 assertNullPointerException(() -> MethodInvokers.asBiFunction(null));
51 }
5253 @Test
54void testFullExample() throws SecurityException, ReflectiveOperationException {
55final Method method = String.class.getMethod("charAt", int.class);
56final BiFunction<String, Integer, Character> function = MethodInvokers.asBiFunction(method);
57 assertEquals('C', function.apply("ABC", 2));
58 }
5960 @Test
61void testToString() throws SecurityException, ReflectiveOperationException {
62// Should not blow up and must return _something_63 assertFalse(MethodInvokers.asBiFunction(getMethodForGetString1Arg()).toString().isEmpty());
64 }
6566 }