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.arguments.IntegerArgument;
21 public class ParserTest {
26 public void setUp() throws Exception {
27 parser = new Parser();
31 public void testParse() {
33 // define allowed parameters
34 final Parameter helpParameter = new Parameter("Show help screen", "-h",
36 parser.addParameter(helpParameter);
38 final Parameter compileParameter = new Parameter("Compile code", "-c",
40 parser.addParameter(compileParameter);
42 final Parameter bitrateParameter = new Parameter(false, true, false,
43 new IntegerArgument(), "Target bitrate", "-b", "--bitrate");
44 parser.addParameter(bitrateParameter);
46 // check help generation
50 parser.parse(new String[] { "--help", "-b", "123" });
52 // --help was in the arguments
53 assertTrue(helpParameter.isParameterSpecified());
55 // compile was not present
56 assertFalse(compileParameter.isParameterSpecified());
58 // bitrate is given as 123
59 assertTrue(bitrateParameter.isParameterSpecified());
61 assertEquals(123, (int) bitrateParameter.getArgumentsAsIntegers()