diff --git a/src/test/java/org/apache/commons/lang3/ObjectUtilsFirstNonNullTest.java b/src/test/java/org/apache/commons/lang3/ObjectUtilsFirstNonNullTest.java new file mode 100644 index 00000000000..a2a4d30a351 --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/ObjectUtilsFirstNonNullTest.java @@ -0,0 +1,49 @@ +/* + * 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 + * + * http://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; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class ObjectUtilsFirstNonNullTest { + + @Test + public void testFirstNonNullWithValidValues() { + String result = ObjectUtils.firstNonNull(null, null, "first", "second"); + assertEquals("first", result); + } + + @Test + public void testFirstNonNullAllNulls() { + String result = ObjectUtils.firstNonNull(null, null, null); + assertNull(result, "Expected result to be null when all inputs are null"); + } + + @Test + public void testFirstNonNullSingleValue() { + Integer value = ObjectUtils.firstNonNull(42); + assertEquals(42, value); + } + + @Test + public void testFirstNonNullWithMixedTypes() { + Number result = ObjectUtils.firstNonNull(null, 3.14, 100L); + assertEquals(3.14, result); + } +} \ No newline at end of file diff --git a/src/test/java/org/apache/commons/lang3/StringsUtilCapitalizeTest.java b/src/test/java/org/apache/commons/lang3/StringsUtilCapitalizeTest.java new file mode 100644 index 00000000000..3389d87bfd2 --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/StringsUtilCapitalizeTest.java @@ -0,0 +1,64 @@ +/* + * 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 + * + * http://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; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import org.junit.jupiter.api.Test; + + +public class StringsUtilCapitalizeTest { + @Test + void capitalize_NormalLowercaseWord_ReturnsCapitalized() { + assertEquals("Hello", StringUtils.capitalize("hello")); + } + + @Test + void capitalize_AlreadyCapitalizedWord_ReturnsSameString() { + assertEquals("Hello", StringUtils.capitalize("Hello")); + } + + @Test + void capitalize_AllUppercaseWord_ReturnsSameString() { + assertEquals("HELLO", StringUtils.capitalize("HELLO")); + } + + @Test + void capitalize_EmptyString_ReturnsSameString() { + assertEquals("", StringUtils.capitalize("")); + } + + @Test + void capitalize_NullInput_ReturnsNull() { + assertNull(StringUtils.capitalize(null)); + } + + @Test + void capitalize_SingleLowercaseChar_ReturnsCapitalizedChar() { + assertEquals("A", StringUtils.capitalize("a")); + } + + @Test + void capitalize_NonLetterFirstChar_ReturnsSameString() { + assertEquals("1hello", StringUtils.capitalize("1hello")); + } + + @Test + void capitalize_WhitespaceOnly_ReturnsSameString() { + assertEquals(" ", StringUtils.capitalize(" ")); + } +} diff --git a/src/test/java/org/apache/commons/lang3/UtilsStringIntegrationTest.java b/src/test/java/org/apache/commons/lang3/UtilsStringIntegrationTest.java new file mode 100644 index 00000000000..01ce55934ff --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/UtilsStringIntegrationTest.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * http://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; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class UtilsStringIntegrationTest { + + + @Test + public void testTextNormalizationScenario() { + String rawInput = " Héllò Wórld! "; + + //Trim the string (removes leading/trailing whitespace) + String trimmed = StringUtils.trim(rawInput); + assertEquals("Héllò Wórld!", trimmed, "Trim step failed"); + + //Remove accents (Héllò → Hello, Wórld → World) + String noAccents = StringUtils.stripAccents(trimmed); + assertEquals("Hello World!", noAccents, "Accent stripping failed"); + + //Normalize internal whitespace (collapse multiple spaces to one) + String normalizedSpace = StringUtils.normalizeSpace(noAccents); + assertEquals("Hello World!", normalizedSpace, "Space normalization failed"); + + //Convert to lowercase + String finalResult = normalizedSpace.toLowerCase(); + assertEquals("hello world!", finalResult, "Lowercasing failed"); + } +} diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsIsCreatableTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsIsCreatableTest.java new file mode 100644 index 00000000000..2a650d3be4e --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsIsCreatableTest.java @@ -0,0 +1,52 @@ +/* + * 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 + * + * http://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.math; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class NumberUtilsIsCreatableTest { + + @Test + public void testValidIntegers() { + assertTrue(NumberUtils.isCreatable("123")); + assertTrue(NumberUtils.isCreatable("-456")); + assertTrue(NumberUtils.isCreatable("+789")); + } + + @Test + public void testValidDecimalNumbers() { + assertTrue(NumberUtils.isCreatable("123.456")); + assertTrue(NumberUtils.isCreatable("-0.001")); + assertTrue(NumberUtils.isCreatable(".5")); + assertTrue(NumberUtils.isCreatable("5.")); + } + + @Test + public void testScientificNotation() { + assertTrue(NumberUtils.isCreatable("1e10")); + assertTrue(NumberUtils.isCreatable("-2.5E-3")); + } + + @Test + public void testHexAndOctal() { + assertTrue(NumberUtils.isCreatable("0xFF")); + assertTrue(NumberUtils.isCreatable("0Xabc")); + assertTrue(NumberUtils.isCreatable("0777")); // treated as octal + } +} \ No newline at end of file