@@ -37,65 +37,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3737
3838public class DefaultParserTest extends AbstractParserTestCase {
3939
40- @ Override
41- @ BeforeEach
42- public void setUp () {
43- super .setUp ();
44- parser = new DefaultParser ();
45- }
46-
47- @ Test
48- public void testBuilder () {
49- // @formatter:off
50- final Builder builder = DefaultParser .builder ()
51- .setStripLeadingAndTrailingQuotes (false )
52- .setAllowPartialMatching (false )
53- .setDeprecatedHandler (null );
54- // @formatter:on
55- parser = builder .build ();
56- assertEquals (DefaultParser .class , parser .getClass ());
57- parser = builder .get ();
58- assertEquals (DefaultParser .class , parser .getClass ());
59- }
60-
61- @ Test
62- public void testDeprecated () throws ParseException {
63- final Set <Option > handler = new HashSet <>();
64- parser = DefaultParser .builder ().setDeprecatedHandler (handler ::add ).build ();
65- final Option opt1 = Option .builder ().option ("d1" ).deprecated ().build ();
66- // @formatter:off
67- final Option opt2 = Option .builder ().option ("d2" ).deprecated (DeprecatedAttributes .builder ()
68- .setForRemoval (true )
69- .setSince ("1.0" )
70- .setDescription ("Do this instead." ).get ()).build ();
71- // @formatter:on
72- final Option opt3 = Option .builder ().option ("a" ).build ();
73- // @formatter:off
74- final CommandLine cl = parser .parse (new Options ()
75- .addOption (opt1 )
76- .addOption (opt2 )
77- .addOption (opt3 ),
78- new String [] {"-d1" , "-d2" , "-a" });
79- // @formatter:on
80- // Trigger handler:
81- assertTrue (cl .hasOption (opt1 .getOpt ()));
82- assertTrue (cl .hasOption (opt2 .getOpt ()));
83- assertTrue (cl .hasOption (opt3 .getOpt ()));
84- // Assert handler was triggered
85- assertTrue (handler .contains (opt1 ));
86- assertTrue (handler .contains (opt2 ));
87- assertFalse (handler .contains (opt3 ));
88- }
89-
90- @ ParameterizedTest (name = "{index}. {0}" )
91- @ ArgumentsSource (ExternalArgumentsProvider .class )
92- public void testParameterized (final String testName , final CommandLineParser parser , final String [] args , final String expected ,
93- final String option , final String message ) throws Exception {
94- final CommandLine cl = parser .parse (options , args );
95-
96- assertEquals (expected , cl .getOptionValue (option ), message );
97- }
98-
9940 static class ExternalArgumentsProvider implements ArgumentsProvider {
10041
10142 @ Override
@@ -209,12 +150,71 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte
209150 }
210151 }
211152
153+ @ Override
154+ @ BeforeEach
155+ public void setUp () {
156+ super .setUp ();
157+ parser = new DefaultParser ();
158+ }
159+
160+ @ Test
161+ public void testBuilder () {
162+ // @formatter:off
163+ final Builder builder = DefaultParser .builder ()
164+ .setStripLeadingAndTrailingQuotes (false )
165+ .setAllowPartialMatching (false )
166+ .setDeprecatedHandler (null );
167+ // @formatter:on
168+ parser = builder .build ();
169+ assertEquals (DefaultParser .class , parser .getClass ());
170+ parser = builder .get ();
171+ assertEquals (DefaultParser .class , parser .getClass ());
172+ }
173+
174+ @ Test
175+ public void testDeprecated () throws ParseException {
176+ final Set <Option > handler = new HashSet <>();
177+ parser = DefaultParser .builder ().setDeprecatedHandler (handler ::add ).build ();
178+ final Option opt1 = Option .builder ().option ("d1" ).deprecated ().build ();
179+ // @formatter:off
180+ final Option opt2 = Option .builder ().option ("d2" ).deprecated (DeprecatedAttributes .builder ()
181+ .setForRemoval (true )
182+ .setSince ("1.0" )
183+ .setDescription ("Do this instead." ).get ()).build ();
184+ // @formatter:on
185+ final Option opt3 = Option .builder ().option ("a" ).build ();
186+ // @formatter:off
187+ final CommandLine cl = parser .parse (new Options ()
188+ .addOption (opt1 )
189+ .addOption (opt2 )
190+ .addOption (opt3 ),
191+ new String [] {"-d1" , "-d2" , "-a" });
192+ // @formatter:on
193+ // Trigger handler:
194+ assertTrue (cl .hasOption (opt1 .getOpt ()));
195+ assertTrue (cl .hasOption (opt2 .getOpt ()));
196+ assertTrue (cl .hasOption (opt3 .getOpt ()));
197+ // Assert handler was triggered
198+ assertTrue (handler .contains (opt1 ));
199+ assertTrue (handler .contains (opt2 ));
200+ assertFalse (handler .contains (opt3 ));
201+ }
202+
212203 @ Override
213204 @ Test
214205 @ Disabled ("Test case handled in the parameterized tests as \" DEFAULT behavior\" " )
215206 public void testLongOptionWithEqualsQuoteHandling () throws Exception {
216207 }
217208
209+ @ ParameterizedTest (name = "{index}. {0}" )
210+ @ ArgumentsSource (ExternalArgumentsProvider .class )
211+ public void testParameterized (final String testName , final CommandLineParser parser , final String [] args , final String expected ,
212+ final String option , final String message ) throws Exception {
213+ final CommandLine cl = parser .parse (options , args );
214+
215+ assertEquals (expected , cl .getOptionValue (option ), message );
216+ }
217+
218218 @ Override
219219 @ Test
220220 @ Disabled ("Test case handled in the parameterized tests as \" DEFAULT behavior\" " )
0 commit comments