2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.commons.commandline.parameterparser;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
16 import org.junit.Before;
17 import org.junit.Test;
19 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
21 public class ParserTest {
26 public void setUp() throws Exception {
27 parser = new Parser();
31 public void testParse() {
33 // define allowed parameters
34 final StringParameter helpParameter = parser
35 .add(new StringParameter("Show help screen"))
36 .addAliases("--help", "-h").setMandatory();
38 final StringParameter compileParameter = parser.add(
39 new StringParameter("Compile code")).addAliases("--compile",
42 // check help generation
46 parser.parse(new String[] { "--help", "section" });
48 // --help was in the arguments
49 assertTrue(helpParameter.isParameterSpecified());
51 // compile was not present
52 assertFalse(compileParameter.isParameterSpecified());
54 // validate that help argument was "section"
55 assertEquals("section", helpParameter.getValue());