From c9068c9999d1c206f328aae93915873658b36174 Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Mon, 24 Mar 2025 22:49:58 -0400 Subject: [PATCH 1/7] Added boundary Value tests for max() method in NumberUtils --- .../lang3/math/NumberUtils_TestPK.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java new file mode 100644 index 00000000000..901c2dd5371 --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java @@ -0,0 +1,44 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +public class NumberUtils_TestPK { + + @ParameterizedTest + @CsvSource({ + "-128 , -128, -128 , -128" , //Test all at min and equal + "127 , 127 , 127 , 127" , //Test all at max and equal value + "0 , 0 , 0 ,0 ", //Test all at typical value + "-128 , -127 , -126, -126", // Test for all min boundary edge cases + "127, 126, 125 , 127", // Test for all max boudary edge cases + "-128, 0, 127, 127", //Test across the entire range + "-128, 126, 127, 127", // Test with edge value with upper limit + "-128, -128, 127, 127" //Test all extreme mix values + + }) + void testMaxByte(byte a, byte b, byte c, byte expected) { + + assertEquals(expected, NumberUtils.max(a,b,c),"Failed for inputs: " + a +"," + b + ", " + c); + } + +} From 634fe528648699ec266ffa26b467de94ee38289c Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Sun, 30 Mar 2025 00:37:06 -0400 Subject: [PATCH 2/7] Add white box test for min () --- .../java/org/apache/StringUtils_TestPK.java | 56 +++++++++++++++++++ .../lang3/math/NumberUtils_TestPK.java | 41 +++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/apache/StringUtils_TestPK.java diff --git a/src/test/java/org/apache/StringUtils_TestPK.java b/src/test/java/org/apache/StringUtils_TestPK.java new file mode 100644 index 00000000000..8544c498e60 --- /dev/null +++ b/src/test/java/org/apache/StringUtils_TestPK.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 + * + * 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; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Test; + +public class StringUtils_TestPK { + + @Test + void testReverseStringIsNull(){ + assertNull(StringUtils.reverse(null)); + } + @Test + void testReverseStringWithSpaces(){ + assertEquals("dlrow olleh", StringUtils.reverse("hello world"), + "Failed test when string is : hello world"); + } + @Test + void testReverseSingleCharacter(){ + assertEquals("p", StringUtils.reverse("p"), + "Failed test when string is : p"); + } + @Test + void testReverseEmptyString(){ + assertEquals(" ", StringUtils.reverse(" "), + " Failed test when string is Emplty"); + } + @Test + void testReverseString(){ + assertEquals("dlrow", StringUtils.reverse("world"), + "Failed test when string is : world"); + } + @Test + void testReverseWhenUpperCaseAndLowerCase(){ + assertEquals("dLroW", StringUtils.reverse("WorLd"), + "Failed test when inout is : WorLd"); + } +} diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java index 901c2dd5371..de1a2193131 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java @@ -19,11 +19,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; public class NumberUtils_TestPK { - + // parametrized test on max() @ParameterizedTest @CsvSource({ "-128 , -128, -128 , -128" , //Test all at min and equal @@ -40,5 +41,41 @@ void testMaxByte(byte a, byte b, byte c, byte expected) { assertEquals(expected, NumberUtils.max(a,b,c),"Failed for inputs: " + a +"," + b + ", " + c); } - + + // white box test on min() + + @Test + void testMinValueNormal(){ + assertEquals(1, NumberUtils.min(5,3,8,1,7)); + } + @Test + void testMinValueAtStart(){ + assertEquals(1, NumberUtils.min(1,5,3,8,7)); + } + @Test + void testMinValueAtEnd(){ + assertEquals(1, NumberUtils.min(5,3,8,7,1)); + } + @Test + void testMinValueWithinNegativeNum(){ + assertEquals(-8, NumberUtils.min(-5,-3,-8,-1,-7)); + } + @Test + void testMinValueWithMixNUmbers(){ + assertEquals(-8, NumberUtils.min(-5,3,-8,1,-7)); + } + @Test + void testMinValueWithSingleElement(){ + assertEquals(7, NumberUtils.min(7)); + } + //checking test for indirectly calling ValidateArray + @Test + void testMinNullArray(){ + assertThrows(NullPointerException.class, () -> NumberUtils.min((int[]) null)); + } + @Test + void testMinEmptyArray(){ + assertThrows(IllegalArgumentException.class, () -> NumberUtils.min ()); + } + } From f8bcafd2d24f960afd99fa208fe3eb74ab7a325b Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Sun, 30 Mar 2025 02:20:38 -0400 Subject: [PATCH 3/7] Updated test file and staged deletion.. added black box tetsing for reverse() --- .../java/org/apache/{ => commons/lang3}/StringUtils_TestPK.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/test/java/org/apache/{ => commons/lang3}/StringUtils_TestPK.java (100%) diff --git a/src/test/java/org/apache/StringUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java similarity index 100% rename from src/test/java/org/apache/StringUtils_TestPK.java rename to src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java From 266e687cc900e6071552c5350ff98553f43137f5 Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Mon, 7 Apr 2025 00:18:01 -0400 Subject: [PATCH 4/7] Add Parametrized BOundary Value test in CharUtils_TestPK --- .../commons/lang3/CharUtils_TestPK.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/java/org/apache/commons/lang3/CharUtils_TestPK.java diff --git a/src/test/java/org/apache/commons/lang3/CharUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/CharUtils_TestPK.java new file mode 100644 index 00000000000..9d3ff859c8e --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/CharUtils_TestPK.java @@ -0,0 +1,43 @@ + +/* + * 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 org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +public class CharUtils_TestPK { + + @ParameterizedTest + @CsvSource({ + "'A', \\u0041" , //Printable ASCII + "' ', \\u0020" , //Space Character + "'0', \\u0030" , //Digit Character + "'z', \\u007a" , //Lowercase AsCII + "'\u0000', \\u0000", // Minimum Unicode (null character) + "'\uFFFF', \\uffff" ,// Maximum Unicode (U+FFFF) + "'\u007F', \\u007f" // Last ASCII control character + + }) + void testToUnicodeEscaped_char(char input, String expected){ + assertEquals(expected, CharUtils.unicodeEscaped(input)); + + } + +} From 15dac093d43c8f0ef17f2c9949a7def2663edd46 Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Mon, 7 Apr 2025 00:34:52 -0400 Subject: [PATCH 5/7] updating --- src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java index 8544c498e60..3351c3f2f50 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java +++ b/src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache; +package org.apache.commons.lang3; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; From 488343ada999fd6ee2d660e7e979d0d410d1d9b5 Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Sat, 12 Apr 2025 01:31:10 -0400 Subject: [PATCH 6/7] Replace NumberUtils_TestPK with NumberUtils_Test --- ...tils_TestPK.java => NumberUtils_Test.java} | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) rename src/test/java/org/apache/commons/lang3/math/{NumberUtils_TestPK.java => NumberUtils_Test.java} (64%) diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/math/NumberUtils_Test.java similarity index 64% rename from src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java rename to src/test/java/org/apache/commons/lang3/math/NumberUtils_Test.java index de1a2193131..f6abc9cd88e 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtils_TestPK.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtils_Test.java @@ -17,13 +17,19 @@ package org.apache.commons.lang3.math; 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 static org.junit.jupiter.api.Assertions.assertTrue; +import java.math.BigDecimal; + +import org.apache.commons.lang3.ObjectUtils.Null; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -public class NumberUtils_TestPK { +public class NumberUtils_Test { // parametrized test on max() @ParameterizedTest @CsvSource({ @@ -78,4 +84,36 @@ void testMinEmptyArray(){ assertThrows(IllegalArgumentException.class, () -> NumberUtils.min ()); } + //unit test on createBigDecimal() + @Test + void testCreateBigDecimalHasNullInput(){ + //test with input as null + assertEquals(null,NumberUtils.createBigDecimal(null), + "Expected null when input is null"); + } + @Test + void testCreateBigDecimalIsEmptyString(){ + assertThrows(NumberFormatException.class, () -> { + NumberUtils.createBigDecimal(""); + }, "Expected NumberFormatException when input is empty string"); + } + @Test + void testCreateBigDecimalIsBlankString(){ + assertThrows(NumberFormatException.class, () -> { + NumberUtils.createBigDecimal(" "); + }, "Expected NumberFormatException when input is a blank string"); + } + @Test + void testCreateBigDecimalHasValidInput(){ + BigDecimal result = NumberUtils.createBigDecimal("123.45"); + assertNotNull(result, "Expected a valid BigDecimal Object"); + assertEquals(new BigDecimal("123.45"), result, + "Expected BigDecimal value to be 123.45"); + } + @Test + void testCreateBigDecimalHasInvalidInput(){ + assertThrows(NumberFormatException.class, () -> { + NumberUtils.createBigDecimal("abc"); + }, "Expected NumberFormatException when input is non-numeric string"); + } } From 1e5f99162930a5c77d5d8daeb7da0d9be11b183d Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Sat, 12 Apr 2025 01:46:55 -0400 Subject: [PATCH 7/7] Add CharUtils_Test.java and StringUtils_Test.java, remove old PK versions --- .../commons/lang3/{CharUtils_TestPK.java => CharUtils_Test.java} | 0 .../lang3/{StringUtils_TestPK.java => StringUtils_Test.java} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/test/java/org/apache/commons/lang3/{CharUtils_TestPK.java => CharUtils_Test.java} (100%) rename src/test/java/org/apache/commons/lang3/{StringUtils_TestPK.java => StringUtils_Test.java} (100%) diff --git a/src/test/java/org/apache/commons/lang3/CharUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/CharUtils_Test.java similarity index 100% rename from src/test/java/org/apache/commons/lang3/CharUtils_TestPK.java rename to src/test/java/org/apache/commons/lang3/CharUtils_Test.java diff --git a/src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java b/src/test/java/org/apache/commons/lang3/StringUtils_Test.java similarity index 100% rename from src/test/java/org/apache/commons/lang3/StringUtils_TestPK.java rename to src/test/java/org/apache/commons/lang3/StringUtils_Test.java