@@ -40,6 +40,39 @@ Licensed to the Apache Software Foundation (ASF) under one or more
4040public class HelpFormatterTest {
4141 private static final String EOL = System .lineSeparator ();
4242
43+ static Stream <Arguments > deprecatedOptionsProvider () {
44+ List <Arguments > lst = new ArrayList <>();
45+ Option option = Option .builder ("a" ).longOpt ("aaa" ).desc ("dddd dddd dddd" )
46+ .deprecated (DeprecatedAttributes .builder ().setForRemoval (true ).setSince ("now" )
47+ .setDescription ("Why why why" ).get ())
48+ .build ();
49+
50+ HelpFormatter hf = HelpFormatter .builder ().setShowDeprecated (false ).get ();
51+ lst .add (Arguments .of (hf , option , "dddd dddd dddd" ));
52+
53+ hf = HelpFormatter .builder ().setShowDeprecated (true ).get ();
54+ lst .add (Arguments .of (hf , option , "[Deprecated] dddd dddd dddd" ));
55+
56+ hf = HelpFormatter .builder ().setShowDeprecated ((d , o ) -> String .format ("%s [%s]" , d , o .getDeprecated ())).get ();
57+ lst .add (Arguments .of (hf , option , "dddd dddd dddd [Deprecated for removal since now: Why why why]" ));
58+
59+ option = Option .builder ("a" ).longOpt ("aaa" )
60+ .deprecated (DeprecatedAttributes .builder ().setForRemoval (true ).setSince ("now" )
61+ .setDescription ("Why why why" ).get ())
62+ .build ();
63+
64+ hf = HelpFormatter .builder ().setShowDeprecated (false ).get ();
65+ lst .add (Arguments .of (hf , option , "" ));
66+
67+ hf = HelpFormatter .builder ().setShowDeprecated (true ).get ();
68+ lst .add (Arguments .of (hf , option , "[Deprecated]" ));
69+
70+ hf = HelpFormatter .builder ().setShowDeprecated ((d , o ) -> String .format ("%s [%s]" , d , o .getDeprecated ())).get ();
71+ lst .add (Arguments .of (hf , option , "[Deprecated for removal since now: Why why why]" ));
72+
73+ return lst .stream ();
74+ }
75+
4376 @ Test
4477 public void testAccessors () {
4578 final HelpFormatter formatter = new HelpFormatter ();
@@ -366,6 +399,26 @@ public void testOptionWithoutShortFormat2() {
366399 //@formatter:on
367400 }
368401
402+ @ ParameterizedTest
403+ @ MethodSource ("deprecatedOptionsProvider" )
404+ public void testPrintDeprecatedOptions (final HelpFormatter hf , final Option option , final String expectedTxt ) {
405+ final StringBuffer sb = new StringBuffer ();
406+
407+ final int leftPad = 1 ;
408+ final int descPad = 3 ;
409+ final String lpad = hf .createPadding (leftPad );
410+ final String dpad = hf .createPadding (descPad );
411+ Options options ;
412+ String expected = lpad + "-a,--aaa" ;
413+
414+ options = new Options ().addOption (option );
415+ if (expectedTxt .length () > 0 ) {
416+ expected = expected + dpad + expectedTxt ;
417+ }
418+ hf .renderOptions (sb , 160 , options , leftPad , descPad );
419+ assertEquals (expected , sb .toString ());
420+ }
421+
369422 @ Test
370423 public void testPrintHelpNewlineFooter () {
371424 final HelpFormatter formatter = new HelpFormatter ();
@@ -490,59 +543,6 @@ public void testPrintOptions() {
490543 assertEquals (expected , sb .toString (), "multiple wrapped options" );
491544 }
492545
493- @ ParameterizedTest
494- @ MethodSource ("deprecatedOptionsProvider" )
495- public void testPrintDeprecatedOptions (final HelpFormatter hf , final Option option , final String expectedTxt ) {
496- final StringBuffer sb = new StringBuffer ();
497-
498- final int leftPad = 1 ;
499- final int descPad = 3 ;
500- final String lpad = hf .createPadding (leftPad );
501- final String dpad = hf .createPadding (descPad );
502- Options options ;
503- String expected = lpad + "-a,--aaa" ;
504-
505- options = new Options ().addOption (option );
506- if (expectedTxt .length () > 0 ) {
507- expected = expected + dpad + expectedTxt ;
508- }
509- hf .renderOptions (sb , 160 , options , leftPad , descPad );
510- assertEquals (expected , sb .toString ());
511- }
512-
513- static Stream <Arguments > deprecatedOptionsProvider () {
514- List <Arguments > lst = new ArrayList <>();
515- Option option = Option .builder ("a" ).longOpt ("aaa" ).desc ("dddd dddd dddd" )
516- .deprecated (DeprecatedAttributes .builder ().setForRemoval (true ).setSince ("now" )
517- .setDescription ("Why why why" ).get ())
518- .build ();
519-
520- HelpFormatter hf = HelpFormatter .builder ().setShowDeprecated (false ).get ();
521- lst .add (Arguments .of (hf , option , "dddd dddd dddd" ));
522-
523- hf = HelpFormatter .builder ().setShowDeprecated (true ).get ();
524- lst .add (Arguments .of (hf , option , "[Deprecated] dddd dddd dddd" ));
525-
526- hf = HelpFormatter .builder ().setShowDeprecated ((d , o ) -> String .format ("%s [%s]" , d , o .getDeprecated ())).get ();
527- lst .add (Arguments .of (hf , option , "dddd dddd dddd [Deprecated for removal since now: Why why why]" ));
528-
529- option = Option .builder ("a" ).longOpt ("aaa" )
530- .deprecated (DeprecatedAttributes .builder ().setForRemoval (true ).setSince ("now" )
531- .setDescription ("Why why why" ).get ())
532- .build ();
533-
534- hf = HelpFormatter .builder ().setShowDeprecated (false ).get ();
535- lst .add (Arguments .of (hf , option , "" ));
536-
537- hf = HelpFormatter .builder ().setShowDeprecated (true ).get ();
538- lst .add (Arguments .of (hf , option , "[Deprecated]" ));
539-
540- hf = HelpFormatter .builder ().setShowDeprecated ((d , o ) -> String .format ("%s [%s]" , d , o .getDeprecated ())).get ();
541- lst .add (Arguments .of (hf , option , "[Deprecated for removal since now: Why why why]" ));
542-
543- return lst .stream ();
544- }
545-
546546 @ Test
547547 public void testPrintOptionWithEmptyArgNameUsage () {
548548 final Option option = new Option ("f" , true , null );
0 commit comments