StringUtil { public static String defaultIfNull(String text) { return defaultIfNull(text, ""); }  static String collapsePathDots(String path); static boolean isNotBlank(String text); static boolean isBlank(String text); static boolean isEmpty(String text); static boolean endsWithIgnoreCase(String source, String suffix); static String defaultIfNull(String text); static String defaultIfNull(String text, String defaultValue); static boolean equals(String text1, String text2); static String toString(Object... keyValues); static int hashCode(String... values); static String substringBefore(String text, char separator); static String substringBeforeLast(String text, char separator); static String substringAfterLast(String text, char separator); static String substringAfter(String text, char c);  }
@Test public void testDefaultIfNull() { Object[] testData = new Object[] { null, "", "", "", " ", " ", "foo", "foo" }; for (int i = 0; i < testData.length; i += 2) { String actualResult = StringUtil .defaultIfNull((String) testData[i]); String expectedResult = (String) testData[i + 1]; assertEquals((i / 2) + " : " + testData[i], expectedResult, actualResult); } }
@Test public void testDefaultIfNull_with_default() { Object[] testData = new Object[] { null, null, null, "", null, "", null, "", "", "foo", "", "foo", "", "foo", "", " ", " ", " ", null, "foo", "foo", }; for (int i = 0; i < testData.length; i += 3) { String actualResult = StringUtil.defaultIfNull( (String) testData[i], (String) testData[i + 1]); String expectedResult = (String) testData[i + 2]; assertEquals( (i / 3) + " : " + testData[i] + ", " + testData[i + 1], expectedResult, actualResult); } }