@Test(groups = "fast") public void testMissing() { CliCommand.Builder command = new CliCommand.Builder("test", "A test"); command.addOption("-v"); try { parser(command); Assert.fail("expected exception"); } catch (ErrorMessage e) { Assert.assertEquals(e.getMessage(), "Missing required option: -v"); } }
@Test(groups = "fast") public void testDuplicate() { CliCommand.Builder command = new CliCommand.Builder("test", "A test"); command.addOption("-v"); try { parser(command, "-v", "foo", "-v=bar"); Assert.fail("expected exception"); } catch (ErrorMessage e) { Assert.assertEquals(e.getMessage(), "Duplicate options: -v=foo, -v=bar"); } }
io.err.println(e.getMessage());
@Test(groups = "fast") public void testUnexpected() { CliCommand.Builder command = new CliCommand.Builder("test", "A test"); command.addOption("-a").withDefault(null); command.addOption("-b").withDefault(null); try { parser(command, "-x", "test", "-a", "hello"); Assert.fail("expected exception"); } catch (ErrorMessage e) { Assert.assertEquals(e.getMessage(), "Unexpected parameters: -x test"); } }
@Test(groups = "fast") public void testMissing() { CliCommand.Builder command = new CliCommand.Builder("test", "A test"); command.addOption("-v"); try { parser(command); Assert.fail("expected exception"); } catch (ErrorMessage e) { Assert.assertEquals(e.getMessage(), "Missing required option: -v"); } }
@Test(groups = "fast") public void testDuplicate() { CliCommand.Builder command = new CliCommand.Builder("test", "A test"); command.addOption("-v"); try { parser(command, "-v", "foo", "-v=bar"); Assert.fail("expected exception"); } catch (ErrorMessage e) { Assert.assertEquals(e.getMessage(), "Duplicate options: -v=foo, -v=bar"); } }
@Test(groups = "fast") public void testUnexpected() { CliCommand.Builder command = new CliCommand.Builder("test", "A test"); command.addOption("-a").withDefault(null); command.addOption("-b").withDefault(null); try { parser(command, "-x", "test", "-a", "hello"); Assert.fail("expected exception"); } catch (ErrorMessage e) { Assert.assertEquals(e.getMessage(), "Unexpected parameters: -x test"); } }