StringUtils { public static String addTrailingIfNeeded(String s, String trailing) { String value = s; if ((null != s) && (null != trailing)) { if (isTruthy(s) && !s.endsWith(trailing)) { value = s + trailing; } } return value; }  static boolean isTruthy(String s); static String addTrailingIfNeeded(String s, String trailing);  }
@Test public void testaddTrailingIfNeededNull() { Assert.assertNull(StringUtils.addTrailingIfNeeded(null, "blah")); }
@Test public void testaddTrailingIfNeededBlank() { Assert.assertEquals("", StringUtils.addTrailingIfNeeded("", "blah")); }
@Test public void testaddTrailingIfNeededNullTrailing() { Assert.assertEquals("hello", StringUtils.addTrailingIfNeeded("hello", null)); }
@Test public void testaddTrailingIfNeeded() { Assert.assertEquals("hello/", StringUtils.addTrailingIfNeeded("hello", "/")); Assert.assertEquals("hello/", StringUtils.addTrailingIfNeeded("hello/", "/")); }