Repository: future-architect/uroborosql
Pull request #219 (2019-11-12 16:50:29)

add UPPER_CASE, LOWER_CASE into CaseFormat

coveralls: 
[![Coverage Status](https://coveralls.io/builds/26941232/badge)](https://coveralls.io/builds/26941232)

Coverage increased (+0.02%) to 85.623% when pulling **1fd44e961bc1d885ca81ec0dc3ed88cb8fba241a on futa23:features/add_caseformat_simple_upper_lower_case** into **317ead0a80bf7f00a11b836e0d86a4b1f3b970e5 on future-architect:master**.


Patch:
diff --git a/src/main/java/jp/co/future/uroborosql/utils/CaseFormat.java b/src/main/java/jp/co/future/uroborosql/utils/CaseFormat.java
index 17474e8..52e80e2 100644
--- a/src/main/java/jp/co/future/uroborosql/utils/CaseFormat.java
+++ b/src/main/java/jp/co/future/uroborosql/utils/CaseFormat.java
@@ -52,8 +52,7 @@ public enum CaseFormat {
 					char ch = str.charAt(i);
 					if (i == 0 && ('a' <= ch && ch <= 'z' || '0' <= ch && ch <= '9')) {
 						builder.append(Character.toUpperCase(str.charAt(i)));
-					}
-					else if (ch == '_') {
+					} else if (ch == '_') {
 						i++;
 						if (i < len) {
 							builder.append(Character.toUpperCase(str.charAt(i)));
@@ -162,6 +161,7 @@ public enum CaseFormat {
 				} else if (ch == '_') {
 					builder.append('_');
 				}
+				// does not support for multibyte characters
 			}
 			return builder.toString();
 		}
@@ -207,9 +207,34 @@ public enum CaseFormat {
 				} else if (ch == '_') {
 					builder.append('_');
 				}
+				// does not support for multibyte characters
 			}
 			return builder.toString();
 		}
+	},
+
+	/** 単純大文字化 */
+	UPPER_CASE {
+
+		@Override
+		public String convert(String original) {
+			if (original == null || "".equals(original)) {
+				return "";
+			}
+			return original.trim().toUpperCase();
+		}
+	},
+
+	/** 単純小文字化 */
+	LOWER_CASE {
+
+		@Override
+		public String convert(String original) {
+			if (original == null || "".equals(original)) {
+				return "";
+			}
+			return original.trim().toLowerCase();
+		}
 	};
 
 	/**


Test patch:
diff --git a/src/test/java/jp/co/future/uroborosql/utils/CaseFormatTest.java b/src/test/java/jp/co/future/uroborosql/utils/CaseFormatTest.java
index 62bdee2..545343a 100644
--- a/src/test/java/jp/co/future/uroborosql/utils/CaseFormatTest.java
+++ b/src/test/java/jp/co/future/uroborosql/utils/CaseFormatTest.java
@@ -71,4 +71,32 @@ public class CaseFormatTest {
 		assertEquals("", CaseFormat.CAMEL_CASE.convert(" "));
 	}
 
+	@Test
+	public void testToUpper() {
+		assertEquals("SNAKE", CaseFormat.UPPER_CASE.convert("snake"));
+		assertEquals("CONVERTTOSNAKE", CaseFormat.UPPER_CASE.convert("convertToSnake"));
+		assertEquals("CONVERTTOSNAKE", CaseFormat.UPPER_CASE.convert("ConvertToSnake"));
+		assertEquals("CONVERT_TO_SNAKE", CaseFormat.UPPER_CASE.convert("convert_to_snake"));
+		assertEquals("CONVERT_TO_SNAKE", CaseFormat.UPPER_CASE.convert("CONVERT_TO_SNAKE"));
+		assertEquals("SNAKE", CaseFormat.UPPER_CASE.convert("SNAKE"));
+		assertEquals("TOSNAKE", CaseFormat.UPPER_CASE.convert("toSnake"));
+		assertEquals("", CaseFormat.UPPER_CASE.convert(null));
+		assertEquals("", CaseFormat.UPPER_CASE.convert(""));
+		assertEquals("", CaseFormat.UPPER_CASE.convert(" "));
+	}
+
+	@Test
+	public void testToLower() {
+		assertEquals("snake", CaseFormat.LOWER_CASE.convert("snake"));
+		assertEquals("converttosnake", CaseFormat.LOWER_CASE.convert("convertToSnake"));
+		assertEquals("converttosnake", CaseFormat.LOWER_CASE.convert("ConvertToSnake"));
+		assertEquals("convert_to_snake", CaseFormat.LOWER_CASE.convert("convert_to_snake"));
+		assertEquals("convert_to_snake", CaseFormat.LOWER_CASE.convert("CONVERT_TO_SNAKE"));
+		assertEquals("snake", CaseFormat.LOWER_CASE.convert("SNAKE"));
+		assertEquals("tosnake", CaseFormat.LOWER_CASE.convert("toSnake"));
+		assertEquals("", CaseFormat.LOWER_CASE.convert(null));
+		assertEquals("", CaseFormat.LOWER_CASE.convert(""));
+		assertEquals("", CaseFormat.LOWER_CASE.convert(" "));
+	}
+
 }