CommandLineSupport { public static String quote(final String arg) { final StringBuilder escaped = new StringBuilder(); for (final char c : arg.toCharArray()) { if (c == QUOTE || c == SLASH) { escaped.append(SLASH); } escaped.append(c); } if (arg.indexOf(BLANK) != -1 || arg.indexOf(QUOTE) != -1) { escaped.insert(0, QUOTE).append(QUOTE); } return escaped.toString(); }  static String quote(final String arg); static String quote(final List<String> args); static List<String> split(final String commandline);  }
@Test public void testQuote1() { assertEquals("aBc", CommandLineSupport.quote("aBc")); }
@Test public void testQuote2() { assertEquals("\"a c\"", CommandLineSupport.quote("a c")); }
@Test public void testQuote3() { assertEquals("\"a\\\"c\"", CommandLineSupport.quote("a\"c")); }
@Test public void testQuote4() { assertEquals("\" xy \"", CommandLineSupport.quote(" xy ")); }
@Test public void testQuote5() { assertEquals("a\\\\b", CommandLineSupport.quote("a\\b")); }
@Test public void testQuoteList1() { assertEquals("", CommandLineSupport.quote(Arrays.<String>asList())); }
@Test public void testQuoteList2() { assertEquals("a", CommandLineSupport.quote(Arrays.asList("a"))); }
@Test public void testQuoteList3() { assertEquals("a b c", CommandLineSupport.quote(Arrays.asList("a", "b", "c"))); }
@Test public void testQuoteList4() { assertEquals("a \"b b\" c", CommandLineSupport.quote(Arrays.asList("a", "b b", "c"))); }