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