package eu.svjatoslav.commons.commandline.parameterparser;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
+import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
import org.junit.Before;
import org.junit.Test;
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
+import static org.junit.Assert.*;
public class ParserTest {
- Parser parser;
+ Parser parser;
- @Before
- public void setUp() throws Exception {
- parser = new Parser();
- }
+ @Before
+ public void setUp() throws Exception {
+ parser = new Parser();
+ }
- @Test
- public void testParse() {
+ @Test
+ public void testParse() {
- // define allowed parameters
- final StringParameter helpParameter = parser
- .add(new StringParameter("Show help screen"))
- .addAliases("--help", "-h").setMandatory();
+ // define allowed parameters
+ final StringParameter helpParameter = parser
+ .add(new StringParameter("Show help screen"))
+ .addAliases("--help", "-h").setMandatory();
- final StringParameter compileParameter = parser.add(
- new StringParameter("Compile code")).addAliases("--compile",
- "-c");
+ final StringParameter compileParameter = parser.add(
+ new StringParameter("Compile code")).addAliases("--compile",
+ "-c");
- // check help generation
- parser.showHelp();
+ // check help generation
+ parser.showHelp();
- // parse arguments
- parser.parse(new String[] { "--help", "section" });
+ // parse arguments
+ parser.parse(new String[]{"--help", "section"});
- // --help was in the arguments
- assertTrue(helpParameter.isParameterSpecified());
+ // --help was in the arguments
+ assertTrue(helpParameter.isParameterSpecified());
- // compile was not present
- assertFalse(compileParameter.isParameterSpecified());
+ // compile was not present
+ assertFalse(compileParameter.isParameterSpecified());
- // validate that help argument was "section"
- assertEquals("section", helpParameter.getValue());
+ // validate that help argument was "section"
+ assertEquals("section", helpParameter.getValue());
- }
+ }
}