2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright (C) 2012, 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 2 of the GNU General Public License
7 * 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.createStringParameter(
35 "Show help screen").addAliases("--help", "-h");
37 final StringParameter compileParameter = parser.createStringParameter(
38 "Compile code").addAliases("--compile", "-c");
40 // check help generation
44 parser.parse(new String[] { "--help", "section" });
46 // --help was in the arguments
47 assertTrue(helpParameter.isParameterSpecified());
49 // compile was not present
50 assertFalse(compileParameter.isParameterSpecified());
52 // validate that help argument was "section"
53 assertEquals("section", helpParameter.getValue());