Claudenw commented on code in PR #552:
URL: https://github.com/apache/commons-text/pull/552#discussion_r1614873256


##########
src/test/java/org/apache/commons/text/CasedStringTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.apache.commons.text.CasedString.StringCase;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class CasedStringTest {
+
+    private static String helloWorldValue(StringCase stringCase) {
+        switch (stringCase) {
+            case CAMEL:
+                return "helloWorld";
+            case KEBAB:
+                return "hello-World";
+            case PHRASE:
+                return "hello World";
+            case SNAKE:
+                return "hello_World";
+            case DOT:
+                return "hello.World";
+            default:
+                fail("Unsupported StringCase: " + stringCase);
+        }
+        return null; // keeps compiler happy
+    }
+
+    private static final CasedString CAMEL = new CasedString(StringCase.CAMEL, 
"aCamelString");
+    private static final CasedString PHRASE = new 
CasedString(StringCase.PHRASE, "A test PhrAse");
+    private static final CasedString KEBAB = new CasedString(StringCase.KEBAB, 
"A-kebAb-string");
+    private static final CasedString SNAKE = new CasedString(StringCase.SNAKE, 
"A_snaKE_string");
+    private static final CasedString DOT = new CasedString(StringCase.DOT, 
"A.dOt.string");
+    private static final CasedString ABCDEF = new 
CasedString(StringCase.PHRASE, "a  b  c  @def");
+    /**
+     * tests the conversion from each Cased string type to every other type.
+     * @param underTest the CasedString being tested.
+     */
+    @ParameterizedTest
+    @MethodSource("conversionProvider")
+    public void testCrossProductConversions(CasedString underTest) {
+        for (StringCase stringCase : StringCase.values()) {
+            assertEquals(helloWorldValue(stringCase), 
underTest.toCase(stringCase), () -> "failed converting to " + stringCase);
+        }
+    }
+    /* generates the hello world Cased String for every StringCase */
+    private static Stream<Arguments> conversionProvider() {
+        List<Arguments> lst = new ArrayList<>();
+        for (StringCase stringCase : StringCase.values()) {
+            lst.add(Arguments.of(new CasedString(stringCase, 
helloWorldValue(stringCase))));
+        }
+        return lst.stream();
+    }
+
+    @Test
+    public void testNullConstructor() {
+        for (StringCase stringCase : StringCase.values()) {
+            CasedString underTest = new CasedString(stringCase, null);
+            assertThat(underTest.toString()).isNull();
+            assertThat(underTest.getSegments()).isEmpty();
+            // test a null underTest can convert to all others types.
+            for (CasedString.StringCase otherCase : StringCase.values()) {
+                assertThat(underTest.toCase(otherCase)).isNull();
+            }
+        }
+    }
+
+    @Test
+    public void testToCamelCase() {
+        assertThat(new CasedString(StringCase.CAMEL, 
"").toString()).isEqualTo("");
+        assertThat(new CasedString(StringCase.CAMEL, "  
").toString()).isEqualTo("");
+        assertThat(new CasedString(StringCase.CAMEL, 
"Tocamelcase").toString()).isEqualTo("tocamelcase");

Review Comment:
   I cam across a reference that says camel case is lower case first character 
and pascal case is upper case first character.  to create a java method name 
use 
   ```
   CasedString cString = new CasedString(StringCase.....
   String javaClassName = 
WordUtils.capitalise(cCstring.toCase(StringCase.CAMEL));
   String javaVarName = cString.toCase(StringCase.CAMEL));
   ```
   
   Alternatively we could add PASCAL case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to