@@ -37,17 +37,18 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3737 * Abstract test case testing common parser features.
3838 */
3939public abstract class AbstractParserTestCase {
40+
4041 protected CommandLineParser parser ;
4142
4243 protected Options options ;
4344
4445 @ SuppressWarnings ("deprecation" )
45- private CommandLine parse (final CommandLineParser parser , final Options opts , final String [] args , final Properties properties ) throws ParseException {
46+ private CommandLine parse (final CommandLineParser parser , final Options options , final String [] args , final Properties properties ) throws ParseException {
4647 if (parser instanceof Parser ) {
47- return ((Parser ) parser ).parse (opts , args , properties );
48+ return ((Parser ) parser ).parse (options , args , properties );
4849 }
4950 if (parser instanceof DefaultParser ) {
50- return ((DefaultParser ) parser ).parse (opts , args , properties );
51+ return ((DefaultParser ) parser ).parse (options , args , properties );
5152 }
5253 throw new UnsupportedOperationException ("Default options not supported by this parser" );
5354 }
@@ -482,47 +483,47 @@ public void testNegativeOption() throws Exception {
482483
483484 @ Test
484485 public void testOptionalArgsOptionBuilder () throws Exception {
485- final Options opts = new Options ();
486- opts .addOption (OptionBuilder .hasOptionalArgs (2 ).create ('i' ));
486+ final Options options = new Options ();
487+ options .addOption (OptionBuilder .hasOptionalArgs (2 ).create ('i' ));
487488 final Properties properties = new Properties ();
488489
489- CommandLine cmd = parse (parser , opts , new String []{"-i" }, properties );
490+ CommandLine cmd = parse (parser , options , new String []{"-i" }, properties );
490491 assertTrue (cmd .hasOption ("i" ));
491492 assertNull (cmd .getOptionValues ("i" ));
492493
493- cmd = parse (parser , opts , new String []{"-i" , "paper" }, properties );
494+ cmd = parse (parser , options , new String []{"-i" , "paper" }, properties );
494495 assertTrue (cmd .hasOption ("i" ));
495496 assertArrayEquals (new String []{"paper" }, cmd .getOptionValues ("i" ));
496497
497- cmd = parse (parser , opts , new String []{"-i" , "paper" , "scissors" }, properties );
498+ cmd = parse (parser , options , new String []{"-i" , "paper" , "scissors" }, properties );
498499 assertTrue (cmd .hasOption ("i" ));
499500 assertArrayEquals (new String []{"paper" , "scissors" }, cmd .getOptionValues ("i" ));
500501
501- cmd = parse (parser , opts , new String []{"-i" , "paper" , "scissors" , "rock" }, properties );
502+ cmd = parse (parser , options , new String []{"-i" , "paper" , "scissors" , "rock" }, properties );
502503 assertTrue (cmd .hasOption ("i" ));
503504 assertArrayEquals (new String []{"paper" , "scissors" }, cmd .getOptionValues ("i" ));
504505 assertArrayEquals (new String []{"rock" }, cmd .getArgs ());
505506 }
506507
507508 @ Test
508509 public void testOptionalArgsOptionDotBuilder () throws Exception {
509- final Options opts = new Options ();
510- opts .addOption (Option .builder ("i" ).numberOfArgs (2 ).optionalArg (true ).build ());
510+ final Options options = new Options ();
511+ options .addOption (Option .builder ("i" ).numberOfArgs (2 ).optionalArg (true ).build ());
511512 final Properties properties = new Properties ();
512513
513- CommandLine cmd = parse (parser , opts , new String []{"-i" }, properties );
514+ CommandLine cmd = parse (parser , options , new String []{"-i" }, properties );
514515 assertTrue (cmd .hasOption ("i" ));
515516 assertNull (cmd .getOptionValues ("i" ));
516517
517- cmd = parse (parser , opts , new String []{"-i" , "paper" }, properties );
518+ cmd = parse (parser , options , new String []{"-i" , "paper" }, properties );
518519 assertTrue (cmd .hasOption ("i" ));
519520 assertArrayEquals (new String []{"paper" }, cmd .getOptionValues ("i" ));
520521
521- cmd = parse (parser , opts , new String []{"-i" , "paper" , "scissors" }, properties );
522+ cmd = parse (parser , options , new String []{"-i" , "paper" , "scissors" }, properties );
522523 assertTrue (cmd .hasOption ("i" ));
523524 assertArrayEquals (new String []{"paper" , "scissors" }, cmd .getOptionValues ("i" ));
524525
525- cmd = parse (parser , opts , new String []{"-i" , "paper" , "scissors" , "rock" }, properties );
526+ cmd = parse (parser , options , new String []{"-i" , "paper" , "scissors" , "rock" }, properties );
526527 assertTrue (cmd .hasOption ("i" ));
527528 assertArrayEquals (new String []{"paper" , "scissors" }, cmd .getOptionValues ("i" ));
528529 assertArrayEquals (new String []{"rock" }, cmd .getArgs ());
@@ -630,17 +631,17 @@ public void testPropertiesOption2() throws Exception {
630631
631632 @ Test
632633 public void testPropertyOptionFlags () throws Exception {
633- final Options opts = new Options ();
634- opts .addOption ("a" , false , "toggle -a" );
635- opts .addOption ("c" , "c" , false , "toggle -c" );
636- opts .addOption (OptionBuilder .hasOptionalArg ().create ('e' ));
634+ final Options options = new Options ();
635+ options .addOption ("a" , false , "toggle -a" );
636+ options .addOption ("c" , "c" , false , "toggle -c" );
637+ options .addOption (OptionBuilder .hasOptionalArg ().create ('e' ));
637638
638639 Properties properties = new Properties ();
639640 properties .setProperty ("a" , "true" );
640641 properties .setProperty ("c" , "yes" );
641642 properties .setProperty ("e" , "1" );
642643
643- CommandLine cmd = parse (parser , opts , null , properties );
644+ CommandLine cmd = parse (parser , options , null , properties );
644645 assertTrue (cmd .hasOption ("a" ));
645646 assertTrue (cmd .hasOption ("c" ));
646647 assertTrue (cmd .hasOption ("e" ));
@@ -650,7 +651,7 @@ public void testPropertyOptionFlags() throws Exception {
650651 properties .setProperty ("c" , "no" );
651652 properties .setProperty ("e" , "0" );
652653
653- cmd = parse (parser , opts , null , properties );
654+ cmd = parse (parser , options , null , properties );
654655 assertFalse (cmd .hasOption ("a" ));
655656 assertFalse (cmd .hasOption ("c" ));
656657 assertTrue (cmd .hasOption ("e" )); // this option accepts an argument
@@ -660,7 +661,7 @@ public void testPropertyOptionFlags() throws Exception {
660661 properties .setProperty ("c" , "nO" );
661662 properties .setProperty ("e" , "TrUe" );
662663
663- cmd = parse (parser , opts , null , properties );
664+ cmd = parse (parser , options , null , properties );
664665 assertTrue (cmd .hasOption ("a" ));
665666 assertFalse (cmd .hasOption ("c" ));
666667 assertTrue (cmd .hasOption ("e" ));
@@ -669,7 +670,7 @@ public void testPropertyOptionFlags() throws Exception {
669670 properties .setProperty ("a" , "just a string" );
670671 properties .setProperty ("e" , "" );
671672
672- cmd = parse (parser , opts , null , properties );
673+ cmd = parse (parser , options , null , properties );
673674 assertFalse (cmd .hasOption ("a" ));
674675 assertFalse (cmd .hasOption ("c" ));
675676 assertTrue (cmd .hasOption ("e" ));
@@ -678,32 +679,32 @@ public void testPropertyOptionFlags() throws Exception {
678679 properties .setProperty ("a" , "0" );
679680 properties .setProperty ("c" , "1" );
680681
681- cmd = parse (parser , opts , null , properties );
682+ cmd = parse (parser , options , null , properties );
682683 assertFalse (cmd .hasOption ("a" ));
683684 assertTrue (cmd .hasOption ("c" ));
684685 }
685686
686687 @ Test
687688 public void testPropertyOptionGroup () throws Exception {
688- final Options opts = new Options ();
689+ final Options options = new Options ();
689690
690691 final OptionGroup group1 = new OptionGroup ();
691692 group1 .addOption (new Option ("a" , null ));
692693 group1 .addOption (new Option ("b" , null ));
693- opts .addOptionGroup (group1 );
694+ options .addOptionGroup (group1 );
694695
695696 final OptionGroup group2 = new OptionGroup ();
696697 group2 .addOption (new Option ("x" , null ));
697698 group2 .addOption (new Option ("y" , null ));
698- opts .addOptionGroup (group2 );
699+ options .addOptionGroup (group2 );
699700
700701 final String [] args = {"-a" };
701702
702703 final Properties properties = new Properties ();
703704 properties .put ("b" , "true" );
704705 properties .put ("x" , "true" );
705706
706- final CommandLine cmd = parse (parser , opts , args , properties );
707+ final CommandLine cmd = parse (parser , options , args , properties );
707708
708709 assertTrue (cmd .hasOption ("a" ));
709710 assertFalse (cmd .hasOption ("b" ));
@@ -713,54 +714,54 @@ public void testPropertyOptionGroup() throws Exception {
713714
714715 @ Test
715716 public void testPropertyOptionMultipleValues () throws Exception {
716- final Options opts = new Options ();
717- opts .addOption (OptionBuilder .hasArgs ().withValueSeparator (',' ).create ('k' ));
717+ final Options options = new Options ();
718+ options .addOption (OptionBuilder .hasArgs ().withValueSeparator (',' ).create ('k' ));
718719
719720 final Properties properties = new Properties ();
720721 properties .setProperty ("k" , "one,two" );
721722
722723 final String [] values = {"one" , "two" };
723724
724- final CommandLine cmd = parse (parser , opts , null , properties );
725+ final CommandLine cmd = parse (parser , options , null , properties );
725726 assertTrue (cmd .hasOption ("k" ));
726727 assertArrayEquals (values , cmd .getOptionValues ('k' ));
727728 }
728729
729730 @ Test
730731 public void testPropertyOptionRequired () throws Exception {
731- final Options opts = new Options ();
732- opts .addOption (OptionBuilder .isRequired ().create ("f" ));
732+ final Options options = new Options ();
733+ options .addOption (OptionBuilder .isRequired ().create ("f" ));
733734
734735 final Properties properties = new Properties ();
735736 properties .setProperty ("f" , "true" );
736737
737- final CommandLine cmd = parse (parser , opts , null , properties );
738+ final CommandLine cmd = parse (parser , options , null , properties );
738739 assertTrue (cmd .hasOption ("f" ));
739740 }
740741
741742 @ Test
742743 public void testPropertyOptionSingularValue () throws Exception {
743- final Options opts = new Options ();
744- opts .addOption (OptionBuilder .hasOptionalArgs (2 ).withLongOpt ("hide" ).create ());
744+ final Options options = new Options ();
745+ options .addOption (OptionBuilder .hasOptionalArgs (2 ).withLongOpt ("hide" ).create ());
745746
746747 final Properties properties = new Properties ();
747748 properties .setProperty ("hide" , "seek" );
748749
749- final CommandLine cmd = parse (parser , opts , null , properties );
750+ final CommandLine cmd = parse (parser , options , null , properties );
750751 assertTrue (cmd .hasOption ("hide" ));
751752 assertEquals ("seek" , cmd .getOptionValue ("hide" ));
752753 assertFalse (cmd .hasOption ("fake" ));
753754 }
754755
755756 @ Test
756757 public void testPropertyOptionUnexpected () throws Exception {
757- final Options opts = new Options ();
758+ final Options options = new Options ();
758759
759760 final Properties properties = new Properties ();
760761 properties .setProperty ("f" , "true" );
761762
762763 try {
763- parse (parser , opts , null , properties );
764+ parse (parser , options , null , properties );
764765 fail ("UnrecognizedOptionException expected" );
765766 } catch (final UnrecognizedOptionException e ) {
766767 // expected
@@ -769,16 +770,16 @@ public void testPropertyOptionUnexpected() throws Exception {
769770
770771 @ Test
771772 public void testPropertyOverrideValues () throws Exception {
772- final Options opts = new Options ();
773- opts .addOption (OptionBuilder .hasOptionalArgs (2 ).create ('i' ));
774- opts .addOption (OptionBuilder .hasOptionalArgs ().create ('j' ));
773+ final Options options = new Options ();
774+ options .addOption (OptionBuilder .hasOptionalArgs (2 ).create ('i' ));
775+ options .addOption (OptionBuilder .hasOptionalArgs ().create ('j' ));
775776
776777 final String [] args = {"-j" , "found" , "-i" , "ink" };
777778
778779 final Properties properties = new Properties ();
779780 properties .setProperty ("j" , "seek" );
780781
781- final CommandLine cmd = parse (parser , opts , args , properties );
782+ final CommandLine cmd = parse (parser , options , args , properties );
782783 assertTrue (cmd .hasOption ("j" ));
783784 assertEquals ("found" , cmd .getOptionValue ("j" ));
784785 assertTrue (cmd .hasOption ("i" ));
@@ -788,15 +789,15 @@ public void testPropertyOverrideValues() throws Exception {
788789
789790 @ Test
790791 public void testReuseOptionsTwice () throws Exception {
791- final Options opts = new Options ();
792- opts .addOption (OptionBuilder .isRequired ().create ('v' ));
792+ final Options options = new Options ();
793+ options .addOption (OptionBuilder .isRequired ().create ('v' ));
793794
794795 // first parsing
795- parser .parse (opts , new String [] {"-v" });
796+ parser .parse (options , new String [] {"-v" });
796797
797798 try {
798799 // second parsing, with the same Options instance and an invalid command line
799- parser .parse (opts , new String [0 ]);
800+ parser .parse (options , new String [0 ]);
800801 fail ("MissingOptionException not thrown" );
801802 } catch (final MissingOptionException e ) {
802803 // expected
0 commit comments