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.junit.jupiter.api.Assertions.assertEquals;
21importstatic org.junit.jupiter.api.Assertions.assertFalse;
22importstatic org.junit.jupiter.api.Assertions.assertNotNull;
23importstatic org.junit.jupiter.api.Assertions.assertThrows;
24importstatic org.junit.jupiter.api.Assertions.assertTrue;
2526import java.io.IOException;
2728import org.apache.commons.lang3.AbstractLangTest;
29import org.junit.jupiter.api.Test;
3031/**32 * Tests {@link FailableToBooleanFunction}.33 */34classFailableToBooleanFunctionTestextendsAbstractLangTest {
3536 @Test
37void testApplyAsBoolean_returnsTrue() throws IOException {
38final FailableToBooleanFunction<String, IOException> f = s -> !s.isEmpty();
39 assertTrue(f.applyAsBoolean("hello"));
40 assertFalse(f.applyAsBoolean(""));
41 }
4243 @Test
44void testApplyAsBoolean_throwsException() {
45final IOException expected = new IOException("fail");
46final FailableToBooleanFunction<String, IOException> f = s -> {
47throw expected;
48 };
49final IOException thrown = assertThrows(IOException.class, () -> f.applyAsBoolean("x"));
50 assertEquals(expected, thrown);
51 }
5253 @Test
54void testNop_applyAsBooleanReturnsFalse() throws Throwable {
55 assertFalse(FailableToBooleanFunction.nop().applyAsBoolean("x"));
56 }
5758 @Test
59void testNop_returnsNonNull() {
60 assertNotNull(FailableToBooleanFunction.nop());
61 }
62 }