StringUtils { public static String restrictToMaxFieldLength(String value, Class<?> clazz, String fieldName) { if (value == null) { return null; } else { int maxLength = ClassUtils.getMaxLength(clazz, fieldName); if (maxLength >= 0 && value.length() > maxLength) { value = value.substring(0, maxLength); } } return value; } private  StringUtils(); static String camelCaseToHumanFriendly(String camelCaseString, boolean capitalize); static String getHtmlLineBreak(); static boolean isValidEmail(String value); static String prependProtocol(String value); static String propertyIdToHumanFriendly(Object propertyId, boolean capitalize); static String restrictToMaxFieldLength(String value, Class<?> clazz, String fieldName); static final String HTML_LINE_BREAK; }
@Test public void testRestrictToMaxFieldLength() { assertNull(StringUtils.restrictToMaxFieldLength(null, TestEntity.class, "name")); String result = StringUtils.restrictToMaxFieldLength("longlonglonglonglonglonglonglonglonglonglong", TestEntity.class, "name"); assertEquals(25, result.length()); result = StringUtils.restrictToMaxFieldLength("shortshort", TestEntity.class, "name"); assertEquals(10, result.length()); result = StringUtils.restrictToMaxFieldLength("longlonglonglonglonglonglonglonglonglonglong", TestEntity.class, "somestring"); assertEquals(44, result.length()); }