Thread: [Japi-cvs] SF.net SVN: japi: [172] libs/argparser/trunk/src/test/net/sf/japi/io/args/ ArgParserTest
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2006-09-25 10:16:34
|
Revision: 172 http://svn.sourceforge.net/japi/?rev=172&view=rev Author: christianhujer Date: 2006-09-25 03:16:26 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Improved test for argument parsing, added new test cases. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:04:00 UTC (rev 171) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:16:26 UTC (rev 172) @@ -1,16 +1,28 @@ package test.net.sf.japi.io.args; -import net.sf.japi.io.args.*; +import net.sf.japi.io.args.ArgParser; +import net.sf.japi.io.args.Command; +import net.sf.japi.io.args.MissingArgumentException; +import net.sf.japi.io.args.Option; +import net.sf.japi.io.args.OptionType; +import net.sf.japi.io.args.RequiredOptionsMissingException; +import net.sf.japi.io.args.TerminalException; +import net.sf.japi.io.args.UnknownOptionException; import java.util.List; import org.junit.Test; import org.junit.Assert; /** * Test for {@link ArgParser}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class ArgParserTest { - public static class MockCommand1 implements Command { + /** + * This MockCommand serves as a command for performing simple tests. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ + public static class MockCommand implements Command { /** The input option value. */ private String input; @@ -49,44 +61,101 @@ return input; } - } // class MockCommand1 + } // class MockCommand + /** + * Tests whether supplying a required option with argument in short form works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test - public void testCommand1A() { - final MockCommand1 command = new MockCommand1(); - ArgParser.simpleParseAndRun(command, "-i", "fooInput"); + public void testCommandWithShortOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } + /** + * Tests whether supplying a required option with argument in long form with separate argument works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test - public void testCommand1B() { - final MockCommand1 command = new MockCommand1(); - ArgParser.simpleParseAndRun(command, "--input", "fooInput"); + public void testCommandWithLongOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "--input", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } + /** + * Tests whether supplying a required option with argument in long form with integrated argument works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test - public void testCommand1C() { - final MockCommand1 command = new MockCommand1(); - ArgParser.simpleParseAndRun(command, "--input=fooInput"); + public void testCommandWithLongOptEq() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "--input=fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } + /** + * Tests whether it's detected that a required option is missing. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test(expected=RequiredOptionsMissingException.class) - public void testCommand1D() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { - final MockCommand1 command = new MockCommand1(); + public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command); } + /** + * Tests whether it's detected that an unknown option was given. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test(expected=UnknownOptionException.class) - public void testCommand1E() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { - final MockCommand1 command = new MockCommand1(); + public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--output"); } + /** + * Tests whether it's detected that the argument of an option that requires an argument is missing. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test(expected=MissingArgumentException.class) - public void testCommand1F() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { - final MockCommand1 command = new MockCommand1(); + public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input"); } + + /** + * Tests whether specifying an option twice works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ + @Test + public void testCommandDuplicateOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "-i", "barBuzz", "-i", "fooInput"); + Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + } + } // class ArgParserTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 10:23:54
|
Revision: 173 http://svn.sourceforge.net/japi/?rev=173&view=rev Author: christianhujer Date: 2006-09-25 03:23:45 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Added new assertions about invocation and arguments of run() method. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:16:26 UTC (rev 172) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:23:45 UTC (rev 173) @@ -27,12 +27,16 @@ /** The input option value. */ private String input; + /** Remembers whether {@link #run(java.util.List<java.lang.String>)} was called. */ + private boolean runCalled; + /** The command line arguments received from the parser. */ private List<String> args; /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) public void run(final List<String> args) { + runCalled = true; this.args = args; } @@ -61,6 +65,14 @@ return input; } + /** + * Return whether run was called. + * @return whether run was called. + */ + public boolean isRunCalled() { + return runCalled; + } + } // class MockCommand /** @@ -75,6 +87,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } /** @@ -89,6 +103,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } /** @@ -103,6 +119,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input=fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } /** @@ -115,7 +133,11 @@ @Test(expected=RequiredOptionsMissingException.class) public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); - ArgParser.parseAndRun(command); + try { + ArgParser.parseAndRun(command); + } finally { + Assert.assertFalse("Run must not be called in exception case.", command.isRunCalled()); + } } /** @@ -128,7 +150,11 @@ @Test(expected=UnknownOptionException.class) public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); - ArgParser.parseAndRun(command, "--output"); + try { + ArgParser.parseAndRun(command, "--output"); + } finally { + Assert.assertFalse("Run must not be called in exception case.", command.isRunCalled()); + } } /** @@ -141,7 +167,11 @@ @Test(expected=MissingArgumentException.class) public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); - ArgParser.parseAndRun(command, "--input"); + try { + ArgParser.parseAndRun(command, "--input"); + } finally { + Assert.assertFalse("Run must not be called in exception case.", command.isRunCalled()); + } } /** @@ -156,6 +186,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-i", "barBuzz", "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } } // class ArgParserTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 11:50:21
|
Revision: 175 http://svn.sourceforge.net/japi/?rev=175&view=rev Author: christianhujer Date: 2006-09-25 04:50:15 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Fixed javadoc error. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 11:49:14 UTC (rev 174) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 11:50:15 UTC (rev 175) @@ -50,7 +50,7 @@ /** * Set the value of the input option. - * @return Value of the input option. + * @param input Value of the input option. */ @Option(type = OptionType.REQUIRED, name = {"i", "input"}) public void setInput(final String input) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 22:42:52
|
Revision: 178 http://svn.sourceforge.net/japi/?rev=178&view=rev Author: christianhujer Date: 2006-09-25 15:42:46 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Changed mock method accessibility to clarify which methods of the mock are mock/test methods. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 22:30:23 UTC (rev 177) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 22:42:46 UTC (rev 178) @@ -44,7 +44,7 @@ * Get the command line arguments. * @return Command line arguments. */ - public List<String> getArgs() { + private List<String> getArgs() { return args; } @@ -61,7 +61,7 @@ * Get the value of the input option. * @return Value of the input option. */ - public String getInput() { + private String getInput() { return input; } @@ -69,7 +69,7 @@ * Return whether run was called. * @return whether run was called. */ - public boolean isRunCalled() { + private boolean isRunCalled() { return runCalled; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-11-29 22:26:09
|
Revision: 239 http://svn.sourceforge.net/japi/?rev=239&view=rev Author: christianhujer Date: 2006-11-29 14:26:05 -0800 (Wed, 29 Nov 2006) Log Message: ----------- Removed warnings. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-29 21:17:00 UTC (rev 238) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-11-29 22:26:05 UTC (rev 239) @@ -11,6 +11,7 @@ import java.util.List; import org.junit.Test; import org.junit.Assert; +import org.jetbrains.annotations.NotNull; /** * Test for {@link ArgParser}. @@ -35,7 +36,7 @@ /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) - public int run(final List<String> args) { + public int run(@NotNull final List<String> args) { runCalled = true; this.args = args; return 0; @@ -87,10 +88,10 @@ /** * Tests whether supplying a required option with argument in short form works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandWithShortOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -103,10 +104,10 @@ /** * Tests whether supplying a required option with argument in long form with separate argument works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandWithLongOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -119,10 +120,10 @@ /** * Tests whether supplying a required option with argument in long form with integrated argument works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandWithLongOptEq() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -135,10 +136,10 @@ /** * Tests whether it's detected that a required option is missing. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (expected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test(expected=RequiredOptionsMissingException.class) public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { @@ -152,10 +153,10 @@ /** * Tests whether it's detected that an unknown option was given. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (expected) + * @throws MissingArgumentException (unexpected) */ @Test(expected=UnknownOptionException.class) public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { @@ -169,10 +170,10 @@ /** * Tests whether it's detected that the argument of an option that requires an argument is missing. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (expected) */ @Test(expected=MissingArgumentException.class) public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { @@ -186,10 +187,10 @@ /** * Tests whether specifying an option twice works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test public void testCommandDuplicateOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { @@ -202,10 +203,10 @@ /** * Tests whether help works. - * @throws RequiredOptionsMissingException - * @throws TerminalException - * @throws UnknownOptionException - * @throws MissingArgumentException + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (expected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) */ @Test(expected = TerminalException.class) public void testHelp() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-07-06 20:51:34
|
Revision: 503 http://svn.sourceforge.net/japi/?rev=503&view=rev Author: christianhujer Date: 2007-07-06 13:51:32 -0700 (Fri, 06 Jul 2007) Log Message: ----------- Added test case for stopping option parsing after "--". Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2007-07-05 21:06:34 UTC (rev 502) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2007-07-06 20:51:32 UTC (rev 503) @@ -19,18 +19,18 @@ package test.net.sf.japi.io.args; +import java.lang.reflect.Method; import java.util.List; import java.util.Set; -import java.lang.reflect.Method; import net.sf.japi.io.args.ArgParser; import net.sf.japi.io.args.BasicCommand; +import net.sf.japi.io.args.Command; import net.sf.japi.io.args.MissingArgumentException; import net.sf.japi.io.args.Option; import net.sf.japi.io.args.OptionType; import net.sf.japi.io.args.RequiredOptionsMissingException; import net.sf.japi.io.args.TerminalException; import net.sf.japi.io.args.UnknownOptionException; -import net.sf.japi.io.args.Command; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Test; @@ -211,6 +211,22 @@ } /** + * Tests whether stopping option parsing with -- works. + * @throws RequiredOptionsMissingException (unexpected) + * @throws TerminalException (unexpected) + * @throws UnknownOptionException (unexpected) + * @throws MissingArgumentException (unexpected) + */ + @Test + public void testStopOptionParsing() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "-i", "foo", "--", "--input"); + final List<String> args = command.getArgs(); + Assert.assertEquals("--input must be stored as argument after --", 1, args.size()); + Assert.assertEquals("--input must be stored as argument after --", "--input", args.get(0)); + } + + /** * This MockCommand serves as a command for performing simple tests. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-08-24 08:02:15
|
Revision: 595 http://japi.svn.sourceforge.net/japi/?rev=595&view=rev Author: christianhujer Date: 2007-08-24 01:02:10 -0700 (Fri, 24 Aug 2007) Log Message: ----------- Fixed test that was not in sync with latest ArgParser change (ArgumentFileNotFoundException). Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2007-08-23 21:44:36 UTC (rev 594) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2007-08-24 08:02:10 UTC (rev 595) @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import net.sf.japi.io.args.ArgParser; +import net.sf.japi.io.args.ArgumentFileNotFoundException; import net.sf.japi.io.args.BasicCommand; import net.sf.japi.io.args.Command; import net.sf.japi.io.args.MissingArgumentException; @@ -88,9 +89,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test - public void testCommandWithShortOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testCommandWithShortOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); @@ -104,9 +106,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test - public void testCommandWithLongOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testCommandWithLongOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); @@ -120,9 +123,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test - public void testCommandWithLongOptEq() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testCommandWithLongOptEq() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input=fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); @@ -136,9 +140,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test(expected = RequiredOptionsMissingException.class) - public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); try { ArgParser.parseAndRun(command); @@ -153,10 +158,11 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1751332&group_id=149894&atid=776740">[ 1751332 ] Required options check should be optional / configurable</a> */ @Test - public void testCommandRequiredOptionMissingDisabled() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + public void testCommandRequiredOptionMissingDisabled() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); command.setCheckRequiredOptions(false); ArgParser.parseAndRun(command); @@ -168,9 +174,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (expected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test(expected = UnknownOptionException.class) - public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); try { ArgParser.parseAndRun(command, "--output"); @@ -185,9 +192,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (expected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test(expected = MissingArgumentException.class) - public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); try { ArgParser.parseAndRun(command, "--input"); @@ -202,9 +210,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test - public void testCommandDuplicateOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testCommandDuplicateOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-i", "barBuzz", "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); @@ -218,9 +227,10 @@ * @throws TerminalException (expected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test(expected = TerminalException.class) - public void testHelp() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testHelp() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-h"); } @@ -231,9 +241,10 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) */ @Test - public void testStopOptionParsing() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testStopOptionParsing() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-i", "foo", "--", "--input"); final List<String> args = command.getArgs(); @@ -247,10 +258,11 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1750193&group_id=149894&atid=776740">[ 1750193 ] Partial read of command line arguments from a file</a> */ @Test - public void testOptionsFromFileSingleLine() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testOptionsFromFileSingleLine() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "@src/test/net/sf/japi/io/args/ArgParserTest_OptionsFileSingleLine"); final List<String> args = command.getArgs(); @@ -267,10 +279,11 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1758846&group_id=149894&atid=776737">[ 1758846 ] Multiple command file inclusion fails</a> */ @Test - public void testOptionsFromFileMultiple() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testOptionsFromFileMultiple() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "@src/test/net/sf/japi/io/args/ArgParserTest_MultipleOptionsFileMaster"); final List<String> args = command.getArgs(); @@ -287,10 +300,11 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1750198&group_id=149894&atid=776740">[ 1750198 ] Allow single dash instead of double dash</a> */ @Test - public void testSingleDashOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testSingleDashOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-input", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); @@ -304,10 +318,11 @@ * @throws TerminalException (unexpected) * @throws UnknownOptionException (unexpected) * @throws MissingArgumentException (unexpected) + * @throws ArgumentFileNotFoundException (unexpected) * @see <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1750198&group_id=149894&atid=776740">[ 1750198 ] Allow single dash instead of double dash</a> */ @Test - public void testSingleDashOptionWithEquals() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + public void testSingleDashOptionWithEquals() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException, ArgumentFileNotFoundException { final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-input=fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); @@ -330,6 +345,9 @@ /** The command line arguments received from the parser. */ private List<String> args; + /** Option value, saved for verification. */ + private String foo; + /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) public int run(@NotNull final List<String> args) { @@ -358,12 +376,20 @@ } /** + * Get the value of the foo option. + * @return Value of the foo option. + */ + public String getFoo() { + return foo; + } + + /** * Set the value of the foo option. * @param foo Value of the foo option. */ @Option({"f", "b", "foo", "bar", "buzz"}) public void setFoo(final String foo) { - // ignored + this.foo = foo; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |