@@ -20,10 +20,11 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2020import static org .junit .jupiter .api .Assertions .assertEquals ;
2121import static org .junit .jupiter .api .Assertions .assertFalse ;
2222import static org .junit .jupiter .api .Assertions .assertNull ;
23+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2324import static org .junit .jupiter .api .Assertions .assertTrue ;
24- import static org .junit .jupiter .api .Assertions .fail ;
2525
2626import org .junit .jupiter .api .Test ;
27+ import org .junit .jupiter .api .function .Executable ;
2728
2829@ SuppressWarnings ("deprecation" ) // OptionBuilder is marked deprecated
2930public class OptionBuilderTest {
@@ -47,20 +48,9 @@ public void testBaseOptionStringOpt() {
4748
4849 @ Test
4950 public void testBuilderIsResettedAlways () {
50- try {
51- OptionBuilder .withDescription ("JUnit" ).create ('"' );
52- fail ("IllegalArgumentException expected" );
53- } catch (final IllegalArgumentException e ) {
54- // expected
55- }
51+ assertThrows (IllegalArgumentException .class , () -> OptionBuilder .withDescription ("JUnit" ).create ('"' ));
5652 assertNull (OptionBuilder .create ('x' ).getDescription (), "we inherited a description" );
57-
58- try {
59- OptionBuilder .withDescription ("JUnit" ).create ();
60- fail ("IllegalArgumentException expected" );
61- } catch (final IllegalArgumentException e ) {
62- // expected
63- }
53+ assertThrows (IllegalArgumentException .class , (Executable ) OptionBuilder ::create );
6454 assertNull (OptionBuilder .create ('x' ).getDescription (), "we inherited a description" );
6555 }
6656
@@ -87,42 +77,19 @@ public void testCompleteOption() {
8777
8878 @ Test
8979 public void testCreateIncompleteOption () {
90- try {
91- OptionBuilder .hasArg ().create ();
92- fail ("Incomplete option should be rejected" );
93- } catch (final IllegalArgumentException e ) {
94- // expected
95-
96- // implicitly reset the builder
97- OptionBuilder .create ("opt" );
98- }
80+ assertThrows (IllegalArgumentException .class , (Executable ) OptionBuilder ::create );
81+ // implicitly reset the builder
82+ OptionBuilder .create ("opt" );
9983 }
10084
10185 @ Test
10286 public void testIllegalOptions () {
10387 // bad single character option
104- try {
105- OptionBuilder .withDescription ("option description" ).create ('"' );
106- fail ("IllegalArgumentException not caught" );
107- } catch (final IllegalArgumentException exp ) {
108- // success
109- }
110-
88+ assertThrows (IllegalArgumentException .class , () -> OptionBuilder .withDescription ("option description" ).create ('"' ));
11189 // bad character in option string
112- try {
113- OptionBuilder .create ("opt`" );
114- fail ("IllegalArgumentException not caught" );
115- } catch (final IllegalArgumentException exp ) {
116- // success
117- }
118-
90+ assertThrows (IllegalArgumentException .class , () -> OptionBuilder .create ("opt`" ));
11991 // valid option
120- try {
121- OptionBuilder .create ("opt" );
122- // success
123- } catch (final IllegalArgumentException exp ) {
124- fail ("IllegalArgumentException caught" );
125- }
92+ OptionBuilder .create ("opt" );
12693 }
12794
12895 @ Test
@@ -140,18 +107,11 @@ public void testSpecialOptChars() throws Exception {
140107 // '?'
141108 final Option opt1 = OptionBuilder .withDescription ("help options" ).create ('?' );
142109 assertEquals ("?" , opt1 .getOpt ());
143-
144110 // '@'
145111 final Option opt2 = OptionBuilder .withDescription ("read from stdin" ).create ('@' );
146112 assertEquals ("@" , opt2 .getOpt ());
147-
148113 // ' '
149- try {
150- OptionBuilder .create (' ' );
151- fail ("IllegalArgumentException not caught" );
152- } catch (final IllegalArgumentException e ) {
153- // success
154- }
114+ assertThrows (IllegalArgumentException .class , () -> OptionBuilder .create (' ' ));
155115 }
156116
157117 @ Test
0 commit comments