|
19 | 19 |
|
20 | 20 | import junit.framework.TestCase; |
21 | 21 |
|
22 | | -public class ArgumentIsOptionTest extends TestCase { |
| 22 | +public class ArgumentIsOptionTest extends TestCase |
| 23 | +{ |
23 | 24 | private Options options = null; |
24 | 25 | private CommandLineParser parser = null; |
25 | 26 |
|
26 | | - public void setUp() { |
27 | | - options = new Options().addOption("p", false, "Option p").addOption("attr", |
28 | | - true, "Option accepts argument"); |
| 27 | + public void setUp() |
| 28 | + { |
| 29 | + options = new Options().addOption("p", false, "Option p").addOption("attr", true, "Option accepts argument"); |
29 | 30 |
|
30 | 31 | parser = new PosixParser(); |
31 | 32 | } |
32 | 33 |
|
33 | | - public void testOptionAndOptionWithArgument() { |
34 | | - String[] args = new String[] { |
| 34 | + public void testOptionAndOptionWithArgument() throws Exception |
| 35 | + { |
| 36 | + String[] args = new String[]{ |
35 | 37 | "-p", |
36 | 38 | "-attr", |
37 | 39 | "p" |
38 | | - }; |
| 40 | + }; |
39 | 41 |
|
40 | | - try { |
41 | | - CommandLine cl = parser.parse(options, args); |
42 | | - assertTrue("Confirm -p is set", cl.hasOption("p")); |
43 | | - assertTrue("Confirm -attr is set", cl.hasOption("attr")); |
44 | | - assertTrue("Confirm arg of -attr", |
| 42 | + CommandLine cl = parser.parse(options, args); |
| 43 | + assertTrue("Confirm -p is set", cl.hasOption("p")); |
| 44 | + assertTrue("Confirm -attr is set", cl.hasOption("attr")); |
| 45 | + assertTrue("Confirm arg of -attr", |
45 | 46 | cl.getOptionValue("attr").equals("p")); |
46 | | - assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0); |
47 | | - } |
48 | | - catch (ParseException e) { |
49 | | - fail(e.toString()); |
50 | | - } |
| 47 | + assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0); |
51 | 48 | } |
52 | 49 |
|
53 | | - public void testOptionWithArgument() { |
54 | | - String[] args = new String[] { |
| 50 | + public void testOptionWithArgument() throws Exception |
| 51 | + { |
| 52 | + String[] args = new String[]{ |
55 | 53 | "-attr", |
56 | 54 | "p" |
57 | | - }; |
| 55 | + }; |
58 | 56 |
|
59 | | - try { |
60 | | - CommandLine cl = parser.parse(options, args); |
61 | | - assertFalse("Confirm -p is set", cl.hasOption("p")); |
62 | | - assertTrue("Confirm -attr is set", cl.hasOption("attr")); |
63 | | - assertTrue("Confirm arg of -attr", |
| 57 | + CommandLine cl = parser.parse(options, args); |
| 58 | + assertFalse("Confirm -p is set", cl.hasOption("p")); |
| 59 | + assertTrue("Confirm -attr is set", cl.hasOption("attr")); |
| 60 | + assertTrue("Confirm arg of -attr", |
64 | 61 | cl.getOptionValue("attr").equals("p")); |
65 | | - assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0); |
66 | | - } |
67 | | - catch (ParseException e) { |
68 | | - fail(e.toString()); |
69 | | - } |
| 62 | + assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0); |
70 | 63 | } |
71 | 64 |
|
72 | | - public void testOption() { |
73 | | - String[] args = new String[] { |
| 65 | + public void testOption() throws Exception |
| 66 | + { |
| 67 | + String[] args = new String[]{ |
74 | 68 | "-p" |
75 | | - }; |
| 69 | + }; |
76 | 70 |
|
77 | | - try { |
78 | | - CommandLine cl = parser.parse(options, args); |
79 | | - assertTrue("Confirm -p is set", cl.hasOption("p")); |
80 | | - assertFalse("Confirm -attr is not set", cl.hasOption("attr")); |
81 | | - assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0); |
82 | | - } |
83 | | - catch (ParseException e) { |
84 | | - fail(e.toString()); |
85 | | - } |
| 71 | + CommandLine cl = parser.parse(options, args); |
| 72 | + assertTrue("Confirm -p is set", cl.hasOption("p")); |
| 73 | + assertFalse("Confirm -attr is not set", cl.hasOption("attr")); |
| 74 | + assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0); |
86 | 75 | } |
87 | 76 | } |
0 commit comments