HerdStringHelper { public String join(List<String> list, String delimiter, String escapeSequence) { String result = null; if (list != null) { List<String> filteredAndEscaped = new ArrayList<>(); for (String element : list) { if (StringUtils.isNotBlank(element)) { element = element.replace(delimiter, escapeSequence + delimiter); filteredAndEscaped.add(element); } } result = StringUtils.join(filteredAndEscaped, delimiter); } return result; }  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 testJoin() { List<String> list = Arrays.asList("A", "B", "C"); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "A|B|C", result); }
@Test public void testJoinEscape() { List<String> list = Arrays.asList("A|", "B|", "C|"); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "A\\||B\\||C\\|", result); }
@Test public void testJoinIgnoreBlanks() { List<String> list = Arrays.asList(" \t\n\r", "A", " \t\n\r", "B", " \t\n\r"); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "A|B", result); }
@Test public void testJoinIgnoreNulls() { List<String> list = Arrays.asList(null, "A", null, "B", null); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "A|B", result); }
@Test public void testJoinSingleElement() { List<String> list = Arrays.asList("A"); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "A", result); }
@Test public void testJoinBlanksOnly() { List<String> list = Arrays.asList(" \t\n\r", null, " \t\n\r", null); String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertEquals("result", "", result); }
@Test public void testJoinListNull() { List<String> list = null; String delimiter = "|"; String escapeSequence = "\\"; String result = herdStringHelper.join(list, delimiter, escapeSequence); assertNull("result", result); }