FieldNameToArrayNotationWithValueFunction implements Function<Field, String> { @VisibleForTesting String camelCaseToUnderscore(String fieldName) { List<Character> chars = newArrayList(asList(fieldName.toCharArray())); for (int i = 0; i < chars.size(); i++) { Character aChar = chars.get(i); if (Character.isUpperCase(aChar)) { chars.remove(i); chars.add(i, Character.toLowerCase(aChar)); chars.add(i, '_'); } } return Joiner.on("").join(chars); } FieldNameToArrayNotationWithValueFunction(T entity); @Override String apply(Field field);  }
@Test public void testCamelCaseToUnderscore() throws Exception { String fieldName = "accountId"; String underscoredName = function.camelCaseToUnderscore(fieldName); assertThat(underscoredName).isEqualTo("account_id"); }