@Test public void testLongWithUnexpectedArgument1() throws Exception { String[] args = new String[] { "--foo=bar" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("foo").create('f')); try { parser.parse(options, args); } catch (UnrecognizedOptionException e) { assertEquals("--foo=bar", e.getOption()); return; } fail("UnrecognizedOptionException not thrown"); }
@Test public void testShortWithUnexpectedArgument() throws Exception { String[] args = new String[] { "-f=bar" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("foo").create('f')); try { parser.parse(options, args); } catch (UnrecognizedOptionException e) { assertEquals("-f=bar", e.getOption()); return; } fail("UnrecognizedOptionException not thrown"); }
@Test public void testLongWithUnexpectedArgument2() throws Exception { String[] args = new String[] { "-foobar" }; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("foo").create('f')); try { parser.parse(options, args); } catch (UnrecognizedOptionException e) { assertEquals("-foobar", e.getOption()); return; } fail("UnrecognizedOptionException not thrown"); }
@Test public void testUnrecognizedOption() throws Exception { String[] args = new String[] { "-a", "-d", "-b", "toast", "foo", "bar" }; try { parser.parse(options, args); fail("UnrecognizedOptionException wasn't thrown"); } catch (UnrecognizedOptionException e) { assertEquals("-d", e.getOption()); } }
@Test public void testUnrecognizedOptionWithBursting() throws Exception { String[] args = new String[] { "-adbtoast", "foo", "bar" }; try { parser.parse(options, args); fail("UnrecognizedOptionException wasn't thrown"); } catch (UnrecognizedOptionException e) { assertEquals("-adbtoast", e.getOption()); } }
throw new ExhibitorCreatorExit("Unknown option: " + e.getOption(), cli);
LOG.error("Unrecognized option: " + e.getOption()); formatter.printHelp("legends", options); System.exit(1);
System.err.println("error: Invalid argument: " + e.getOption()); usage();
throw new ProcessingException(Messages.UNDEFINED_OPTION.format(e.getOption()));