HerdStringUtils { public static Integer convertStringToInteger(final String stringValue, final Integer defaultValue) { if (StringUtils.isNotBlank(stringValue)) { try { return Integer.parseInt(stringValue); } catch (final NumberFormatException e) { throw new IllegalArgumentException(String.format("Failed to convert \"%s\" value to %s.", stringValue, Integer.class.getName()), e); } } else { return defaultValue; } }  static String decodeBase64(String base64EncodedText); static String getShortDescription(String description, Integer shortDescMaxLength); static String stripHtml(String fragment, String... whitelistTags); static void checkCsvInjection(String text, String errorMessage); static Integer convertStringToInteger(final String stringValue, final Integer defaultValue); static String sanitizeLogText(String loggingText); static final String HIDDEN_TEXT; }
@Test public void testConvertStringToInteger() { assertEquals(INTEGER_VALUE, HerdStringUtils.convertStringToInteger(INTEGER_VALUE.toString(), INTEGER_VALUE_2)); }
@Test public void testConvertStringToIntegerBlankStringValue() { assertEquals(INTEGER_VALUE, HerdStringUtils.convertStringToInteger(null, INTEGER_VALUE)); assertEquals(INTEGER_VALUE, HerdStringUtils.convertStringToInteger(EMPTY_STRING, INTEGER_VALUE)); }
@Test public void testConvertStringToIntegerInvalidIntegerValue() { try { HerdStringUtils.convertStringToInteger(INVALID_INTEGER_VALUE, INTEGER_VALUE); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Failed to convert \"%s\" value to %s.", INVALID_INTEGER_VALUE, Integer.class.getName()), e.getMessage()); } }