StringUtils { public static String appendOptional(String first, String second) { return appendOptional(first, second, null); } private  StringUtils(); static String appendOptional(String first, String second); static String appendOptional(String first, String second, String separator); static String strJoin(List<String> entries, String separator); static int addLineSeparator(SpannableStringBuilder sb, boolean force); static int addLineSeparator(SpannableStringBuilder sb); static Spanned createSpannedHtmlLink(String name, String url); static final String COMMA_SEPARATOR; static final String LINE_SEPARATOR; static final String HTML_LINE_SEPARATOR; static final String ZERO_WIDTH_SPACE; }
@Test public void should_append_two_strings() { String first = "Hello, "; String second = "World!"; String result = StringUtils.appendOptional(first, second); assertThat(result).isEqualTo("Hello, World!"); }
@Test public void should_not_append_string_if_one_is_null() { String expected = "hello"; String res1 = StringUtils.appendOptional(null, expected); String res2 = StringUtils.appendOptional(expected, null); assertThat(res1).isEqualTo(res2); assertThat(res1).isEqualTo(expected); }
@Test public void should_append_with_a_separator() { String first = "Hello"; String second = "World!"; String separator = ", "; String result = StringUtils.appendOptional(first, second, separator); assertThat(result).isEqualTo("Hello, World!"); }