Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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(" "));
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}