JAL-2189 apply license
[jalview.git] / test / jalview / bin / ArgsParserTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.bin;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNull;
26 import static org.testng.AssertJUnit.assertTrue;
27
28 import org.testng.annotations.Test;
29
30 public class ArgsParserTest
31 {
32   @Test(groups = "Functional")
33   public void testGetValue()
34   {
35     ArgsParser ap = new ArgsParser(new String[] { "-name", "Henry", "-job",
36         "Tester" });
37     assertEquals(4, ap.getSize());
38     assertNull(ap.getValue("rubbish"));
39     assertEquals("Tester", ap.getValue("job"));
40     // call to getValue removes the argument and its value
41     assertEquals(2, ap.getSize());
42     assertNull(ap.getValue("job"));
43     assertFalse(ap.contains("job"));
44     assertFalse(ap.contains("Tester"));
45
46     assertEquals("Henry", ap.getValue("name"));
47     assertEquals(0, ap.getSize());
48     assertNull(ap.getValue("name"));
49   }
50
51   @Test(groups = "Functional")
52   public void testGetValue_decoded()
53   {
54     ArgsParser ap = new ArgsParser(new String[] { "-name%241", "Henry",
55         "-job", "Test%203%2a" });
56     // parameter value is decoded
57     assertEquals("Test 3*", ap.getValue("job", true));
58     // parameter name is not decoded
59     assertNull(ap.getValue("name$1", true));
60     assertEquals("Henry", ap.getValue("name%241", true));
61   }
62
63   @Test(groups = "Functional")
64   public void testNextValue()
65   {
66     ArgsParser ap = new ArgsParser(new String[] { "-name", "Henry", "-job",
67         "Tester" });
68     assertEquals("name", ap.nextValue());
69     assertEquals("Henry", ap.nextValue());
70     assertEquals("job", ap.nextValue());
71     assertEquals("Tester", ap.nextValue());
72   }
73
74   @Test(groups = "Functional")
75   public void testContains()
76   {
77     ArgsParser ap = new ArgsParser(new String[] { "-name", "Henry", "-job",
78         "Tester" });
79     assertFalse(ap.contains("Susan"));
80     assertFalse(ap.contains("-name"));
81     assertTrue(ap.contains("name"));
82     // testing for contains removes the argument
83     assertFalse(ap.contains("name"));
84   }
85 }