View Javadoc

1   package org.apache.torque.generator.processor.string;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.assertEquals;
23  
24  
25  import org.apache.torque.generator.processor.string.Camelbacker;
26  import org.junit.Before;
27  import org.junit.Test;
28  
29  public class CamelbackerTest
30  {
31      Camelbacker camelbacker;
32  
33      @Before
34      public void setUp()
35      {
36          camelbacker = new Camelbacker();
37      }
38  
39      @Test
40      public void testDefault()
41      {
42          String result = camelbacker.process("prOcess-ing_Test");
43          assertEquals("ProcessIngTest", result);
44      }
45  
46      @Test
47      public void testRemoveWithUppercaseNull()
48      {
49          camelbacker.setRemoveWithUppercase(null);
50          String result = camelbacker.process("prOcess-ing_Test");
51          assertEquals("Process-ing_test", result);
52      }
53  
54      @Test
55      public void testFirstCharacterUppercaseFalse()
56      {
57          camelbacker.setFirstCharUppercase(false);
58          String result = camelbacker.process("prOcess-ing_Test");
59          assertEquals("processIngTest", result);
60  
61          result = camelbacker.process("PrOcess-ing_Test");
62          assertEquals("processIngTest", result);
63  
64          camelbacker.setDefaultLowerCase(false);
65          result = camelbacker.process("PrOcess-ing_Test");
66          assertEquals("PrOcessIngTest", result);
67      }
68  
69      @Test
70      public void testDefaultLowerCaseFalse()
71      {
72          camelbacker.setDefaultLowerCase(false);
73          String result = camelbacker.process("PrOcess-ing_Test");
74          assertEquals("PrOcessIngTest", result);
75      }
76  
77      @Test
78      public void testIgnoreBeforeAfter()
79      {
80          String result = camelbacker.process("pro1cess-ing_te2st");
81          assertEquals("Pro1cessIngTe2st", result);
82  
83          camelbacker.setIgnorePartBefore("1");
84          camelbacker.setIgnorePartAfter("2");
85  
86          result = camelbacker.process("pro1cess-ing_te2st");
87          assertEquals("1cessIngTe2", result);
88  
89          camelbacker.setIgnorePartAfter("1");
90          camelbacker.setIgnorePartBefore("2");
91  
92          result = camelbacker.process("pro1cess-ing_te2st");
93          assertEquals("", result);
94  
95          camelbacker.setIgnorePartAfter("1");
96          camelbacker.setIgnorePartBefore("1");
97  
98          result = camelbacker.process("pro1cess-ing_te2st");
99          assertEquals("1", result);
100 
101         // make sure IgnoreBeforeAfter plays nice with the other rules
102 
103         camelbacker.setRemoveWithoutUppercase("1");
104         camelbacker.setIgnorePartAfter(null);
105 
106         result = camelbacker.process("pro1cess-ing_te2st");
107         assertEquals("cessIngTe2st", result);
108 
109         camelbacker.setIgnorePartAfter("1");
110         camelbacker.setRemoveWithoutUppercase(null);
111         camelbacker.setRemoveWithUppercase("1");
112 
113         result = camelbacker.process("pro1cess-ing_te2st");
114         assertEquals("", result);
115     }
116 }