File tree Expand file tree Collapse file tree
java/org/apache/commons/cli
test/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -295,7 +295,10 @@ private void checkRequiredOptions()
295295 if (requiredOptions .size () > 0 )
296296 {
297297 Iterator iter = requiredOptions .iterator ();
298- StringBuffer buff = new StringBuffer ();
298+ StringBuffer buff = new StringBuffer ("Missing required option" );
299+ buff .append (requiredOptions .size () == 1 ? "" : "s" );
300+ buff .append (": " );
301+
299302
300303 // loop through the required options
301304 while (iter .hasNext ())
Original file line number Diff line number Diff line change @@ -94,7 +94,28 @@ public void testHelpOptions(){
9494 assertTrue ("Everything in help should be in all" ,allOptions .containsAll (helpOptions ));
9595 }
9696
97+ public void testMissingOptionException () throws ParseException {
98+ Options options = new Options ();
99+ options .addOption (OptionBuilder .isRequired ().create ("f" ));
100+ try {
101+ new PosixParser ().parse (options , new String [0 ]);
102+ fail ("Expected MissingOptionException to be thrown" );
103+ } catch (MissingOptionException e ) {
104+ assertEquals ("Missing required option: f" , e .getMessage ());
105+ }
106+ }
97107
108+ public void testMissingOptionsException () throws ParseException {
109+ Options options = new Options ();
110+ options .addOption (OptionBuilder .isRequired ().create ("f" ));
111+ options .addOption (OptionBuilder .isRequired ().create ("x" ));
112+ try {
113+ new PosixParser ().parse (options , new String [0 ]);
114+ fail ("Expected MissingOptionException to be thrown" );
115+ } catch (MissingOptionException e ) {
116+ assertEquals ("Missing required options: fx" , e .getMessage ());
117+ }
118+ }
98119
99120}
100121
You can’t perform that action at this time.
0 commit comments