Ejemplo n.º 1
0
  @Test
  public void testToStrings() throws Exception {
    final CommandLine cl = CommandLine.createCommandLine(EXEC_WITH_SPACES);

    cl.withArg(ARG_SPACES_NOQUOTES);
    cl.withArg(ARG_NOSPACES);
    cl.withArg(ARG_SPACES);

    final String expectedWithQuotes =
        DBL_QUOTE
            + EXEC_WITH_SPACES
            + DBL_QUOTE
            + " "
            + DBL_QUOTE
            + ARG_SPACES_NOQUOTES
            + DBL_QUOTE
            + " "
            + ARG_NOSPACES
            + " "
            + DBL_QUOTE
            + ARG_SPACES
            + DBL_QUOTE;
    assertEquals(expectedWithQuotes, cl.toString());

    assertEquals(expectedWithQuotes.replaceAll(DBL_QUOTE, ""), cl.toStringForDisplay());

    assertEquals("Did the impl of CommandLine.toString() change?", expectedWithQuotes, cl + "");
  }
Ejemplo n.º 2
0
  @Test
  public void testToStringWithSeparator() throws Exception {
    final String separator = "], [";
    assertEquals("", CommandLine.toString(null, false, separator));

    assertEquals(
        ARG_SPACES_NOQUOTES,
        CommandLine.toString(new String[] {ARG_SPACES_NOQUOTES}, false, separator));

    assertEquals(
        ARG_SPACES_NOQUOTES + separator + ARG_NOSPACES,
        CommandLine.toString(new String[] {ARG_SPACES_NOQUOTES, ARG_NOSPACES}, false, separator));

    assertEquals(
        ARG_SPACES_NOQUOTES + separator + ARG_NOSPACES + separator + ARG_SPACES,
        CommandLine.toString(
            new String[] {ARG_SPACES_NOQUOTES, ARG_NOSPACES, ARG_SPACES}, false, separator));
  }
Ejemplo n.º 3
0
 @Test
 public void testToStringMisMatchedQuote() {
   final CommandLine cl2 = CommandLine.createCommandLine(EXEC_WITH_SPACES);
   final String argWithMismatchedDblQuote = "argMisMatch='singlequoted\"WithMismatchedDblQuote'";
   cl2.withArg(argWithMismatchedDblQuote);
   assertEquals(
       "Did behavior of mismatched quotes change? Previously it would truncate args.",
       DBL_QUOTE + EXEC_WITH_SPACES + DBL_QUOTE + " ",
       cl2.toString());
 }
Ejemplo n.º 4
0
 @Test
 public void shouldReportPasswordsOnTheLogAsStars() {
   CommandLine line =
       CommandLine.createCommandLine("notexist").withArg(new PasswordArgument("secret"));
   assertThat(line.toString(), not(containsString("secret")));
 }