View Javadoc
1   /*
2    *    Copyright 2016-2025 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.dynamic.sql.util;
17  
18  import static org.assertj.core.api.Assertions.assertThat;
19  
20  import org.junit.jupiter.api.Test;
21  
22  class StringUtilitiesTest {
23  
24      @Test
25      void testInitialUnderscore() {
26          String input = "_USER";
27          assertThat(StringUtilities.toCamelCase(input)).isEqualTo("user");
28      }
29  
30      @Test
31      void testSpace() {
32          String input = "USER NAME";
33          assertThat(StringUtilities.toCamelCase(input)).isEqualTo("userName");
34      }
35  
36      @Test
37      void testNumeric() {
38          String input = "USER%NAME%3";
39          assertThat(StringUtilities.toCamelCase(input)).isEqualTo("userName3");
40      }
41  
42      @Test
43      void testUpperCaseInteger() {
44          Integer i = StringUtilities.upperCaseIfPossible(3);
45          assertThat(i).isEqualTo(3);
46      }
47  
48      @Test
49      void testUpperCaseString() {
50          String i = StringUtilities.upperCaseIfPossible("fred");
51          assertThat(i).isEqualTo("FRED");
52      }
53  }