From 5518c2ddd5f88f396932d55d071c70bd59b1521b Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Tue, 18 Mar 2025 03:04:17 -0400 Subject: [PATCH 1/3] Added WordUtils_TestPk.java test file for first Test case --- .../apache/commons/text/WordUtils_TestPk.java | 200 ++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 src/test/java/org/apache/commons/text/WordUtils_TestPk.java diff --git a/src/test/java/org/apache/commons/text/WordUtils_TestPk.java b/src/test/java/org/apache/commons/text/WordUtils_TestPk.java new file mode 100644 index 0000000000..cd3f813baf --- /dev/null +++ b/src/test/java/org/apache/commons/text/WordUtils_TestPk.java @@ -0,0 +1,200 @@ +/* + * 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.text; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.commons.lang3.StringUtils; + +import org.junit.jupiter.api.Test; + +public class WordUtils_TestPk { + + + + + //Testing empty string and no deliminitor + @Test + public void testCapitalizePartitionEmptyString() { + //setup + + String str=""; + char[] delimiters ={}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("", result); + } + + // testing single lower case string + @Test + public void testCapitalizePartitionLowerCaseString(){ + //set up + String str= "hello"; + char[] delimiters ={}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello", result); + } + //testing multiple lower case string with no deliminator + @Test + public void testCapitalizePartitionMultipleLowerCaseString(){ + //set up + String str= "hello world"; + char[] delimiters ={}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello world", result); + } + // multiple lower case string with a space deliminiter + @Test + public void testCapitalizePartitionMultipleLowerCaseStringWithDeli(){ + //set up + String str= "hello world"; + char[] delimiters ={' '}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello World", result); + } + // words already capitalized with a space deliminiter + @Test + public void testCapitalizePartitionUpperCaseStringWithDeli(){ + //set up + String str= "Hello World"; + char[] delimiters ={' '}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello World", result); + } + // words all capitalized with a multiple deliminiter + @Test + public void testCapitalizePartitionStringWithMultipleDeli(){ + //set up + String str= "hello-world"; + char[] delimiters ={' ','-'}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello-World", result); + } + // words with special character as deliminiter + @Test + public void testCapitalizePartitionWithSpecialDeli(){ + //set up + String str= "hello@world"; + char[] delimiters ={' '}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello@world", result); + } + // words already capitalized with a space deliminiter + @Test + public void testCapitalizePartitionAllUpperCaseWithDeli(){ + //set up + String str= "HELLO WORLD"; + char[] delimiters ={' '}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("HELLO WORLD", result); + } + // words already capitalized with a space deliminiter + @Test + public void testCapitalizePartitionStringWithNumbersWithDeli(){ + //set up + String str= "Hello World"; + char[] delimiters ={' '}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello World", result); + } + // words with a space deliminiter at the start + @Test + public void testCapitalizePartitionWithDeliAtStart(){ + //set up + String str= " hello"; + char[] delimiters ={' '}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals(" Hello", result); + } + // words with a space deliminiter at the end + @Test + public void testCapitalizePartitionWithDeliAtEnd(){ + //set up + String str= "hello "; + char[] delimiters ={' '}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello ", result); + } + // lower case word only first letter is capital with no deliminiter + @Test + public void testCapitalizePartitionNoDeliminiters(){ + //set up + String str= "hello world"; + char[] delimiters ={}; + + //test + String result= WordUtils.capitalize(str, delimiters); + + //verify + + assertEquals("Hello world", result); + } +} From 54fc1c2426e4d3bb80e3983b8bfa727e30ee4bcc Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Sun, 6 Apr 2025 12:27:00 -0400 Subject: [PATCH 2/3] Add White Box test in replace() in StringSubstitutor_TestPK --- .../text/StringSubstitutor_TestPK.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/test/java/org/apache/commons/text/StringSubstitutor_TestPK.java diff --git a/src/test/java/org/apache/commons/text/StringSubstitutor_TestPK.java b/src/test/java/org/apache/commons/text/StringSubstitutor_TestPK.java new file mode 100644 index 0000000000..bf5a8a3a96 --- /dev/null +++ b/src/test/java/org/apache/commons/text/StringSubstitutor_TestPK.java @@ -0,0 +1,71 @@ +/* + * 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.text; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +public class StringSubstitutor_TestPK { + + //test for edge case Null value + + @Test + void testReplace_NullInput() { + StringSubstitutor substitutor = new StringSubstitutor(); + assertNull(substitutor.replace((String) null), "Expected null when input is null"); + } + + // Edge case testing by testing empty string + @Test + void testReplace_EmptyString() { + StringSubstitutor substitutor = new StringSubstitutor(); + assertEquals("", substitutor.replace(""), "Expected empty string to remain empty"); + } + // No placeholder test + @Test + void testReplace_NoPlaceholders() { + StringSubstitutor substitutor = new StringSubstitutor(); + String input = "Hello, World!"; + assertEquals(input, substitutor.replace(input), "Expected the same string when no placeholders exist"); + } + //test valid substitution + @Test + void testReplace_ValidSubstitution() { + Map values = new HashMap<>(); + values.put("name", "Jacob"); + StringSubstitutor substitutor = new StringSubstitutor(values); + + String input = "Hello, ${name}!"; + String expected = "Hello, Jacob!"; + assertEquals(expected, substitutor.replace(input), "Expected placeholder to be replaced"); + } + @Test + void testReplace_UnresolvedPlaceholder() { + Map values = new HashMap<>(); + values.put("name", "Alice"); + StringSubstitutor substitutor = new StringSubstitutor(values); + + String input = "Hello, ${unknown}!"; + String expected = "Hello, ${unknown}!"; + assertEquals(expected, substitutor.replace(input), "Expected unresolved placeholder to remain unchanged"); + } +} From e8c94c947c69857ee57f8983d2653f2928417389 Mon Sep 17 00:00:00 2001 From: Jyotprabhs Date: Sat, 12 Apr 2025 01:56:48 -0400 Subject: [PATCH 3/3] Replace StringSubstitutor_TestPK and WordUtils_TestPk with updated test files --- ...{StringSubstitutor_TestPK.java => StringSubstitutor_Test.java} | 0 .../commons/text/{WordUtils_TestPk.java => WordUtils_Test.java} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/test/java/org/apache/commons/text/{StringSubstitutor_TestPK.java => StringSubstitutor_Test.java} (100%) rename src/test/java/org/apache/commons/text/{WordUtils_TestPk.java => WordUtils_Test.java} (100%) diff --git a/src/test/java/org/apache/commons/text/StringSubstitutor_TestPK.java b/src/test/java/org/apache/commons/text/StringSubstitutor_Test.java similarity index 100% rename from src/test/java/org/apache/commons/text/StringSubstitutor_TestPK.java rename to src/test/java/org/apache/commons/text/StringSubstitutor_Test.java diff --git a/src/test/java/org/apache/commons/text/WordUtils_TestPk.java b/src/test/java/org/apache/commons/text/WordUtils_Test.java similarity index 100% rename from src/test/java/org/apache/commons/text/WordUtils_TestPk.java rename to src/test/java/org/apache/commons/text/WordUtils_Test.java