### Question:
Util { public static String underscoredToJava(String name, boolean capitalize) { StringTokenizer st = new StringTokenizer(name, "_"); StringBuilder buf = new StringBuilder(); boolean first = true; while (st.hasMoreTokens()) { String token = st.nextToken(); token = specialCharsToJava(token); int len = token.length(); if (len == 0) { continue; } boolean hasLowerCase = false; boolean hasUpperCase = false; for (int i = 0; i < len && !(hasUpperCase && hasLowerCase); i++) { if (Character.isUpperCase(token.charAt(i))) { hasUpperCase = true; } else if (Character.isLowerCase(token.charAt(i))) { hasLowerCase = true; } } if (hasUpperCase && !hasLowerCase) { token = token.toLowerCase(); } if (first) { first = false; if (capitalize) { buf.append(Character.toUpperCase(token.charAt(0))); } else { buf.append(Character.toLowerCase(token.charAt(0))); } } else { buf.append(Character.toUpperCase(token.charAt(0))); } if (len > 1) { buf.append(token.substring(1, len)); } } return buf.toString(); }  static File toFile(URL url); static String stringFromFile(File file); static String stringFromFile(File file, String joinWith); static String join(Iterable<?> objects, String separator); static String substBackslashes(String string); static Throwable unwindException(Throwable th); static boolean nullSafeEquals(Object o1, Object o2); static int nullSafeCompare(boolean nullsFirst, Comparable<T> o1, T o2); static boolean isEmptyString(CharSequence string); static boolean isBlank(CharSequence cs); static boolean isNumeric(CharSequence cs); static int countMatches(final String str, final String sub); static String capitalized(String name); static String uncapitalized(String aString); @SuppressWarnings("unchecked") static T cloneViaSerialization(T object); static XMLReader createXmlReader(); static Document readDocument(URL url); static String getPackagePath(String className); static String stripPackageName(String className); static Map<K, V> toMap(K[] keys, V[] values); static String extractFileExtension(String fileName); static String stripFileExtension(String fileName); static String stripLineBreaks(String string, char replaceWith); static String encodeXmlAttribute(String string); static String prettyTrim(String str, int maxLength); static Iterator<T> sortedIterator(Iterator<T> it, Comparator<T> comparator); static int hashCode(Collection<?> c); static Pattern sqlPatternToPattern(String pattern, boolean ignoreCase); static boolean isAccessible(Member member); @Deprecated static Class<?> getJavaClass(String className); static String underscoredToJava(String name, boolean capitalize); static String specialCharsToJava(String string);  }### Answer:
@Test public void testUnderscoredToJava1() throws Exception { String expected = "ClassNameIdentifier"; assertEquals(expected, Util.underscoredToJava( "_CLASS_NAME_IDENTIFIER_", true)); }
@Test public void testUnderscoredToJava2() throws Exception { String expected = "propNameIdentifier123"; assertEquals(expected, Util.underscoredToJava( "_prop_name_Identifier_123", false)); }
@Test public void testUnderscoredToJava3() throws Exception { String expected = "lastName"; assertEquals(expected, Util.underscoredToJava("lastName", false)); }
@Test public void testUnderscoredToJava4() throws Exception { String expected = "lastName"; assertEquals(expected, Util.underscoredToJava("LastName", false)); }
@Test public void testUnderscoredToJava5() throws Exception { String expected = "LastName"; assertEquals(expected, Util.underscoredToJava("LastName", true)); }
@Test public void testUnderscoredToJavaSpecialChars() throws Exception { assertEquals("ABCpoundXyz", Util.underscoredToJava("ABC#_XYZ", true)); }