|
28 | 28 | */ |
29 | 29 | public class OptionsTest extends TestCase |
30 | 30 | { |
31 | | - public void testHelpOptions(){ |
32 | | - |
| 31 | + public void testSimple() |
| 32 | + { |
| 33 | + Options opts = new Options(); |
| 34 | + |
| 35 | + opts.addOption("a", false, "toggle -a"); |
| 36 | + opts.addOption("b", true, "toggle -b"); |
| 37 | + |
| 38 | + assertTrue(opts.hasOption("a")); |
| 39 | + assertTrue(opts.hasOption("b")); |
| 40 | + } |
| 41 | + |
| 42 | + public void testDuplicateSimple() |
| 43 | + { |
| 44 | + Options opts = new Options(); |
| 45 | + opts.addOption("a", false, "toggle -a"); |
| 46 | + opts.addOption("a", true, "toggle -a*"); |
| 47 | + |
| 48 | + assertEquals("last one in wins", "toggle -a*", opts.getOption("a").getDescription()); |
| 49 | + } |
| 50 | + |
| 51 | + public void testLong() |
| 52 | + { |
| 53 | + Options opts = new Options(); |
| 54 | + |
| 55 | + opts.addOption("a", "--a", false, "toggle -a"); |
| 56 | + opts.addOption("b", "--b", true, "set -b"); |
| 57 | + |
| 58 | + assertTrue(opts.hasOption("a")); |
| 59 | + assertTrue(opts.hasOption("b")); |
| 60 | + } |
| 61 | + |
| 62 | + public void testDuplicateLong() |
| 63 | + { |
| 64 | + Options opts = new Options(); |
| 65 | + opts.addOption("a", "--a", false, "toggle -a"); |
| 66 | + opts.addOption("a", "--a", false, "toggle -a*"); |
| 67 | + assertEquals("last one in wins", "toggle -a*", opts.getOption("a").getDescription()); |
| 68 | + } |
| 69 | + |
| 70 | + public void testHelpOptions() |
| 71 | + { |
33 | 72 | Option longOnly1 = OptionBuilder.withLongOpt("long-only1").create(); |
34 | 73 | Option longOnly2 = OptionBuilder.withLongOpt("long-only2").create(); |
35 | 74 | Option shortOnly1 = OptionBuilder.create("1"); |
@@ -59,30 +98,39 @@ public void testHelpOptions(){ |
59 | 98 | assertTrue("Everything in help should be in all", allOptions.containsAll(helpOptions)); |
60 | 99 | } |
61 | 100 |
|
62 | | - public void testMissingOptionException() throws ParseException { |
| 101 | + public void testMissingOptionException() throws ParseException |
| 102 | + { |
63 | 103 | Options options = new Options(); |
64 | 104 | options.addOption(OptionBuilder.isRequired().create("f")); |
65 | | - try { |
| 105 | + try |
| 106 | + { |
66 | 107 | new PosixParser().parse(options, new String[0]); |
67 | 108 | fail("Expected MissingOptionException to be thrown"); |
68 | | - } catch (MissingOptionException e) { |
| 109 | + } |
| 110 | + catch (MissingOptionException e) |
| 111 | + { |
69 | 112 | assertEquals("Missing required option: f", e.getMessage()); |
70 | 113 | } |
71 | 114 | } |
72 | 115 |
|
73 | | - public void testMissingOptionsException() throws ParseException { |
| 116 | + public void testMissingOptionsException() throws ParseException |
| 117 | + { |
74 | 118 | Options options = new Options(); |
75 | 119 | options.addOption(OptionBuilder.isRequired().create("f")); |
76 | 120 | options.addOption(OptionBuilder.isRequired().create("x")); |
77 | | - try { |
| 121 | + try |
| 122 | + { |
78 | 123 | new PosixParser().parse(options, new String[0]); |
79 | 124 | fail("Expected MissingOptionException to be thrown"); |
80 | | - } catch (MissingOptionException e) { |
| 125 | + } |
| 126 | + catch (MissingOptionException e) |
| 127 | + { |
81 | 128 | assertEquals("Missing required options: f, x", e.getMessage()); |
82 | 129 | } |
83 | 130 | } |
84 | 131 |
|
85 | | - public void testToString() { |
| 132 | + public void testToString() |
| 133 | + { |
86 | 134 | Options options = new Options(); |
87 | 135 | options.addOption("f", "foo", true, "Foo"); |
88 | 136 | options.addOption("b", "bar", false, "Bar"); |
|
0 commit comments