Added special commandline argument type to support multiple strings.
[svjatoslav_commons.git] / src / test / java / eu / svjatoslav / commons / commandline / parameterparser / ParserTest.java
index 0e654b4..7917a77 100755 (executable)
@@ -1,10 +1,10 @@
 /*
  * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
+ * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
  * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
  */
 
 package eu.svjatoslav.commons.commandline.parameterparser;
@@ -16,7 +16,7 @@ import static org.junit.Assert.assertTrue;
 import org.junit.Before;
 import org.junit.Test;
 
-import eu.svjatoslav.commons.commandline.parameterparser.arguments.IntegerArgument;
+import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
 
 public class ParserTest {
 
@@ -31,23 +31,18 @@ public class ParserTest {
        public void testParse() {
 
                // define allowed parameters
-               final Parameter helpParameter = new Parameter("Show help screen", "-h",
-                               "--help");
-               parser.addParameter(helpParameter);
+               final StringParameter helpParameter = parser
+                               .createStringParameter("Show help screen")
+                               .addAliases("--help", "-h").setMandatory();
 
-               final Parameter compileParameter = new Parameter("Compile code", "-c",
-                               "--compile");
-               parser.addParameter(compileParameter);
-
-               final Parameter bitrateParameter = new Parameter(false, true, false,
-                               new IntegerArgument(), "Target bitrate", "-b", "--bitrate");
-               parser.addParameter(bitrateParameter);
+               final StringParameter compileParameter = parser.createStringParameter(
+                               "Compile code").addAliases("--compile", "-c");
 
                // check help generation
                parser.showHelp();
 
                // parse arguments
-               parser.parse(new String[] { "--help", "-b", "123" });
+               parser.parse(new String[] { "--help", "section" });
 
                // --help was in the arguments
                assertTrue(helpParameter.isParameterSpecified());
@@ -55,11 +50,8 @@ public class ParserTest {
                // compile was not present
                assertFalse(compileParameter.isParameterSpecified());
 
-               // bitrate is given as 123
-               assertTrue(bitrateParameter.isParameterSpecified());
+               // validate that help argument was "section"
+               assertEquals("section", helpParameter.getValue());
 
-               assertEquals(123, (int) bitrateParameter.getArgumentsAsIntegers()
-                               .get(0));
        }
-
 }