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 eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
13 import org.junit.Before;
14 import org.junit.Test;
16 import static org.junit.Assert.*;
18 public class ParserTest {
23 public void setUp() throws Exception {
24 parser = new Parser();
28 public void testParse() {
30 // define allowed parameters
31 final StringParameter helpParameter = parser
32 .add(new StringParameter("Show help screen"))
33 .addAliases("--help", "-h").setMandatory();
35 final StringParameter compileParameter = parser.add(
36 new StringParameter("Compile code")).addAliases("--compile",
39 // check help generation
43 parser.parse(new String[]{"--help", "section"});
45 // --help was in the arguments
46 assertTrue(helpParameter.isParameterSpecified());
48 // compile was not present
49 assertFalse(compileParameter.isParameterSpecified());
51 // validate that help argument was "section"
52 assertEquals("section", helpParameter.getValue());