StringHelper { public static String doubleQuoteIfNecessary(String string) { return string != null && string.contains(" ") &&!string.startsWith("\"") &&!string.endsWith("\"") ? "\"" + string + "\"" : string; }  static String unquote(String string); static String dequote(String string); static String doubleQuoteIfNecessary(String string); static String repeat(String string,
                                int    count); static String trimTrailingWhiteSpace(String string);  }
@Test public void shouldNotDoubleQuoteNullString() { String string = StringHelper.doubleQuoteIfNecessary(null); assertThat(string, is(nullValue())); }
@Test public void shouldNotDoubleQuoteEmptyString() { String string = StringHelper.doubleQuoteIfNecessary(""); assertThat(string, is("")); }
@Test public void shouldNotDoubleQuoteDoubleQuotedString() { String string1 = StringHelper.doubleQuoteIfNecessary("\"\""); assertThat(string1, is("\"\"")); String string2 = StringHelper.doubleQuoteIfNecessary("\"hello\""); assertThat(string2, is("\"hello\"")); String string3 = StringHelper.doubleQuoteIfNecessary("\"hello world\""); assertThat(string3, is("\"hello world\"")); }
@Test public void shouldDoubleQuoteString() { String string1 = StringHelper.doubleQuoteIfNecessary(" "); assertThat(string1, is("\" \"")); String string2 = StringHelper.doubleQuoteIfNecessary("hello"); assertThat(string2, is("hello")); String string3 = StringHelper.doubleQuoteIfNecessary("hello world"); assertThat(string3, is("\"hello world\"")); }