コード例 #1
0
ファイル: BugsTest.java プロジェクト: srnsw/xena
  public void test13935() {
    OptionGroup directions = new OptionGroup();

    Option left = new Option("l", "left", false, "go left");
    Option right = new Option("r", "right", false, "go right");
    Option straight = new Option("s", "straight", false, "go straight");
    Option forward = new Option("f", "forward", false, "go forward");
    forward.setRequired(true);

    directions.addOption(left);
    directions.addOption(right);
    directions.setRequired(true);

    Options opts = new Options();
    opts.addOptionGroup(directions);
    opts.addOption(straight);

    CommandLineParser parser = new PosixParser();
    boolean exception = false;

    String[] args = new String[] {};
    try {
      CommandLine line = parser.parse(opts, args);
    } catch (ParseException exp) {
      exception = true;
    }

    if (!exception) {
      fail("Expected exception not caught.");
    }

    exception = false;

    args = new String[] {"-s"};
    try {
      CommandLine line = parser.parse(opts, args);
    } catch (ParseException exp) {
      exception = true;
    }

    if (!exception) {
      fail("Expected exception not caught.");
    }

    exception = false;

    args = new String[] {"-s", "-l"};
    try {
      CommandLine line = parser.parse(opts, args);
    } catch (ParseException exp) {
      fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
    }

    opts.addOption(forward);
    args = new String[] {"-s", "-l", "-f"};
    try {
      CommandLine line = parser.parse(opts, args);
    } catch (ParseException exp) {
      fail("Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage());
    }
  }