Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.bin

File ArgsParserTest.java

 

Code metrics

0
27
5
1
96
62
5
0.19
5.4
5
1

Classes

Class Line # Actions
ArgsParserTest 33 27 5 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

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