Beispiel #1
0
  public void testHelp() throws Exception {
    TestBean bean = new TestBean();
    CommandLineArguments arguments = CommandLineArguments.createInstance(bean);
    StringWriter strWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(strWriter);
    arguments.help(writer);

    System.out.println(strWriter.toString());
  }
Beispiel #2
0
  public void testShortNameCmd() throws Exception {
    TestBean bean = new TestBean();
    CommandLineArguments arguments = CommandLineArguments.createInstance(bean);
    String[] args = {
      "-b", "1", "-s", "2", "-i", "3", "-l", "4", "-f", "1.0", "-d", "2.0", "-t", "test", "-o"
    };

    arguments.parse(args);
    assertEquals(1, bean.getTestByte());
    assertEquals(2, bean.getTestShort());
    assertEquals(3, bean.getTestInteger());
    assertEquals(4, bean.getTestLong());
    assertEquals(1.0f, bean.getTestFloat());
    assertEquals(2.0d, bean.getTestDouble());
    assertEquals("test", bean.getTestString());
    assertTrue(bean.getTestBoolean());
  }
Beispiel #3
0
  public void testInvalidCmd() throws Exception {
    TestBean bean = new TestBean();
    CommandLineArguments arguments = CommandLineArguments.createInstance(bean);

    try {
      String[] args1 = {"-b", "256"};
      arguments.parse(args1);
      ;
      fail("Must not be possible to parse invalid byte");
    } catch (CommandLineException e) {
    }

    try {
      String[] args1 = {"-s", "65536"};
      arguments.parse(args1);
      ;
      fail("Must not be possible to parse invalid short");
    } catch (CommandLineException e) {
    }

    try {
      String[] args1 = {"-i", "text"};
      arguments.parse(args1);
      ;
      fail("Must not be possible to parse invalid int");
    } catch (CommandLineException e) {
    }

    try {
      String[] args1 = {"-l", "text"};
      arguments.parse(args1);
      ;
      fail("Must not be possible to parse invalid long");
    } catch (CommandLineException e) {
    }

    try {
      String[] args1 = {"-f", "text"};
      arguments.parse(args1);
      ;
      fail("Must not be possible to parse invalid float");
    } catch (CommandLineException e) {
    }

    try {
      String[] args1 = {"-d", "text"};
      arguments.parse(args1);
      ;
      fail("Must not be possible to parse invalid double");
    } catch (CommandLineException e) {
    }
  }
Beispiel #4
0
  public void testLongNameCmd() throws Exception {
    TestBean bean = new TestBean();
    CommandLineArguments arguments = CommandLineArguments.createInstance(bean);
    String[] args = {
      "--testByte=1",
      "--testShort=2",
      "--testInt=3",
      "--testLong=4",
      "--testFloat=1.0",
      "--testDouble=2.0",
      "--testString=test",
      "--testBoolean"
    };

    arguments.parse(args);
    assertEquals(1, bean.getTestByte());
    assertEquals(2, bean.getTestShort());
    assertEquals(3, bean.getTestInteger());
    assertEquals(4, bean.getTestLong());
    assertEquals(1.0f, bean.getTestFloat());
    assertEquals(2.0d, bean.getTestDouble());
    assertEquals("test", bean.getTestString());
    assertTrue(bean.getTestBoolean());
  }