File tree Expand file tree Collapse file tree
main/java/org/apache/commons/cli
test/java/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,13 +17,13 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1717
1818package org .apache .commons .cli ;
1919
20- import java .util .Iterator ;
2120import java .util .List ;
2221
2322/**
2423 * Thrown when a required option has not been provided.
2524 */
2625public class MissingOptionException extends ParseException {
26+
2727 /** This exception {@code serialVersionUID}. */
2828 private static final long serialVersionUID = 8161889051578563249L ;
2929
@@ -34,18 +34,9 @@ public class MissingOptionException extends ParseException {
3434 */
3535 private static String createMessage (final List <?> missingOptions ) {
3636 final StringBuilder buf = new StringBuilder ("Missing required option" );
37- buf .append (missingOptions .size () == 1 ? "" : "s" );
38- buf .append (": " );
39-
40- final Iterator <?> it = missingOptions .iterator ();
41- while (it .hasNext ()) {
42- buf .append (it .next ());
43- if (it .hasNext ()) {
44- buf .append (", " );
45- }
46- }
47-
48- return buf .toString ();
37+ buf .append (missingOptions .size () == 1 ? "" : "s" ).append (": " );
38+ final String string = missingOptions .toString ();
39+ return buf .append (string .substring (1 , string .length () - 1 )).toString ();
4940 }
5041
5142 /** The list of missing options and groups */
Original file line number Diff line number Diff line change @@ -30,6 +30,16 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3030 */
3131public class MissingOptionExceptionTest {
3232
33+ @ Test
34+ void testGetMessage () {
35+ final List <String > originalList = new ArrayList <>();
36+ originalList .add ("optA" );
37+ originalList .add ("optB" );
38+ final MissingOptionException exception = new MissingOptionException (originalList );
39+ assertEquals ("Missing required options: optA, optB" , exception .getMessage ());
40+ assertEquals ("Missing required options: " , new MissingOptionException (new ArrayList <>()).getMessage ());
41+ }
42+
3343 @ Test
3444 void testGetMissingOptions () {
3545 final List <String > originalList = new ArrayList <>();
You can’t perform that action at this time.
0 commit comments