You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/08/12 16:47:32 UTC
svn commit: r984808 - in /myfaces/tobago/trunk/tobago-core/src:
main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java
test/java/org/apache/myfaces/tobago/component/RendererTypesUnitTest.java
Author: lofwyr
Date: Thu Aug 12 14:47:32 2010
New Revision: 984808
URL: http://svn.apache.org/viewvc?rev=984808&view=rev
Log:
test if the constants are consistent
Added:
myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/RendererTypesUnitTest.java
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java?rev=984808&r1=984807&r2=984808&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java Thu Aug 12 14:47:32 2010
@@ -19,6 +19,7 @@ package org.apache.myfaces.tobago.intern
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.StringTokenizer;
public final class StringUtils {
@@ -80,4 +81,19 @@ public final class StringUtils {
}
return indices;
}
+
+ public static String constantToCamelCase(String constant) {
+ final StringBuilder builder = new StringBuilder(constant.length());
+ final char[] chars = constant.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ if (i == 0) {
+ builder.append(chars[i]);
+ } else if (chars[i] == '_') {
+ builder.append(chars[++i]);
+ } else {
+ builder.append((((Character) chars[i]).toString().toLowerCase(Locale.ENGLISH)));
+ }
+ }
+ return builder.toString();
+ }
}
Added: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/RendererTypesUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/RendererTypesUnitTest.java?rev=984808&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/RendererTypesUnitTest.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/RendererTypesUnitTest.java Thu Aug 12 14:47:32 2010
@@ -0,0 +1,37 @@
+package org.apache.myfaces.tobago.component;
+
+/*
+ * 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.
+ */
+
+import org.apache.myfaces.tobago.internal.util.StringUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+public class RendererTypesUnitTest {
+
+ @Test
+ public void testNames() throws IllegalAccessException {
+
+ for (Field field : RendererTypes.class.getFields()) {
+ String value = (String) field.get(null);
+ Assert.assertTrue("value='" + value + "'", value.matches("[A-Z][a-zA-Z]*"));
+ Assert.assertEquals(StringUtils.constantToCamelCase(field.getName()), value);
+ }
+ }
+}