JAL-3438 spotless for 2.11.2.0
[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 jalview.gui.JvOptionPane;
29
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.Test;
32
33 public class ArgsParserTest
34 {
35
36   @BeforeClass(alwaysRun = true)
37   public void setUpJvOptionPane()
38   {
39     JvOptionPane.setInteractiveMode(false);
40     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
41   }
42
43   @Test(groups = "Functional")
44   public void testGetValue()
45   {
46     ArgsParser ap = new ArgsParser(
47             new String[]
48             { "-name", "Henry", "-job", "Tester" });
49     assertEquals(4, ap.getSize());
50     assertNull(ap.getValue("rubbish"));
51     assertEquals("Tester", ap.getValue("job"));
52     // call to getValue removes the argument and its value
53     assertEquals(2, ap.getSize());
54     assertNull(ap.getValue("job"));
55     assertFalse(ap.contains("job"));
56     assertFalse(ap.contains("Tester"));
57
58     assertEquals("Henry", ap.getValue("name"));
59     assertEquals(0, ap.getSize());
60     assertNull(ap.getValue("name"));
61   }
62
63   @Test(groups = "Functional")
64   public void testGetValue_decoded()
65   {
66     ArgsParser ap = new ArgsParser(
67             new String[]
68             { "-name%241", "Henry", "-job", "Test%203%2a" });
69     // parameter value is decoded
70     assertEquals("Test 3*", ap.getValue("job", true));
71     // parameter name is not decoded
72     assertNull(ap.getValue("name$1", true));
73     assertEquals("Henry", ap.getValue("name%241", true));
74   }
75
76   @Test(groups = "Functional")
77   public void testNextValue()
78   {
79     ArgsParser ap = new ArgsParser(
80             new String[]
81             { "-name", "Henry", "-job", "Tester" });
82     assertEquals("name", ap.nextValue());
83     assertEquals("Henry", ap.nextValue());
84     assertEquals("job", ap.nextValue());
85     assertEquals("Tester", ap.nextValue());
86   }
87
88   @Test(groups = "Functional")
89   public void testContains()
90   {
91     ArgsParser ap = new ArgsParser(
92             new String[]
93             { "-name", "Henry", "-job", "Tester" });
94     assertFalse(ap.contains("Susan"));
95     assertFalse(ap.contains("-name"));
96     assertTrue(ap.contains("name"));
97     // testing for contains removes the argument
98     assertFalse(ap.contains("name"));
99   }
100 }