StringHelper { public static String unquote(String string) { string = string != null ? string.trim() : string; return (string != null && ((string.startsWith("\"") && string.endsWith("\"")) || (string.startsWith("'") && string.endsWith("'")))) ? string = string.substring(1, string.length() - 1) : 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 shouldUnquoteNullString() { String string = StringHelper.unquote(null); assertThat(string, is(nullValue())); }
@Test public void shouldUnquoteStringWithoutQuotes() { String string1 = StringHelper.unquote(""); assertThat(string1, is("")); String string2 = StringHelper.unquote("hello"); assertThat(string2, is("hello")); String string3 = StringHelper.unquote("hello world"); assertThat(string3, is("hello world")); }
@Test public void shouldUnquoteSingleQuotedStrings() { String string1 = StringHelper.unquote("\'\'"); assertThat(string1, is("")); String string2 = StringHelper.unquote(" \'\' "); assertThat(string2, is("")); String string3 = StringHelper.unquote("\'hello\'"); assertThat(string3, is("hello")); String string4 = StringHelper.unquote("\'hello world\'"); assertThat(string4, is("hello world")); String string5 = StringHelper.unquote(" \'hello world\' "); assertThat(string5, is("hello world")); }
@Test public void shouldUnquoteDoubleQuotedStrings() { String string1 = StringHelper.unquote("\"\""); assertThat(string1, is("")); String string2 = StringHelper.unquote(" \"\" "); assertThat(string2, is("")); String string3 = StringHelper.unquote("\"hello\""); assertThat(string3, is("hello")); String string4 = StringHelper.unquote("\"hello world\""); assertThat(string4, is("hello world")); String string5 = StringHelper.unquote(" \"hello world\" "); assertThat(string5, is("hello world")); }