HerdStringHelper { public List<String> splitStringWithDefaultDelimiterEscaped(String inputString) { String delimiter = configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER); String escapeChar = configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER_ESCAPE_CHAR); List<String> splitString = new ArrayList<>(); if (StringUtils.isNotBlank(inputString)) { String regex = "(?<!" + Pattern.quote(escapeChar) + ")" + Pattern.quote(delimiter); for (String s : inputString.split(regex)) { splitString.add(s.replace(escapeChar + delimiter, delimiter)); } } return splitString; }  List<String> splitStringWithDefaultDelimiter(String inputString); List<String> splitStringWithDefaultDelimiterEscaped(String inputString); String getRequiredConfigurationValue(ConfigurationValue configurationValue); int getConfigurationValueAsInteger(ConfigurationValue configurationValue); String getConfigurationValueAsString(ConfigurationValue configurationValue); Set<String> splitAndTrim(String string, String delimiter); String join(List<String> list, String delimiter, String escapeSequence); List<String> getDelimitedConfigurationValue(ConfigurationValue configurationValue); String buildStringWithDefaultDelimiter(List<String> inputStrings);  }
@Test public void testSplitStringWithDefaultDelimiterEscapedInputIsNull() { List<String> splitString = herdStringHelper.splitStringWithDefaultDelimiterEscaped(null); assertTrue(splitString.size() == 0); }
@Test public void testSplitStringWithDefaultDelimiterEscapedInputIsEmptyString() { List<String> splitString = herdStringHelper.splitStringWithDefaultDelimiterEscaped(EMPTY_STRING); assertTrue(splitString.size() == 0); }
@Test public void testSplitStringWithDefaultDelimiterEscaped() { String value1 = "arg1"; String value2 = "arg2\\|escaped"; String value2Escaped = "arg2|escaped"; String delimiter = configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER); String delimitedString = value1 + delimiter + value2; List<String> splitString = herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedString); assertTrue(splitString.get(0).equals(value1)); assertTrue(splitString.get(1).equals(value2Escaped)); }