|
21 | 21 | import static org.junit.jupiter.api.Assertions.assertFalse; |
22 | 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
23 | 23 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
24 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue; |
25 | 26 | import static org.junit.jupiter.api.Assertions.fail; |
26 | 27 |
|
|
42 | 43 | import org.apache.commons.cli.ParseException; |
43 | 44 | import org.apache.commons.cli.Parser; |
44 | 45 | import org.apache.commons.cli.PosixParser; |
| 46 | +import org.apache.commons.lang3.ArrayUtils; |
45 | 47 | import org.junit.jupiter.api.Test; |
46 | 48 |
|
47 | 49 | @SuppressWarnings("deprecation") // tests some deprecated classes |
@@ -214,19 +216,10 @@ public void test13425() throws Exception { |
214 | 216 | .hasArg() |
215 | 217 | .create('n'); |
216 | 218 | //@formatter:on |
217 | | - |
218 | 219 | final String[] args = {"-o", "-n", "newpassword"}; |
219 | | - |
220 | 220 | options.addOption(oldpass); |
221 | 221 | options.addOption(newpass); |
222 | | - |
223 | | - final Parser parser = new PosixParser(); |
224 | | - |
225 | | - try { |
226 | | - parser.parse(options, args); |
227 | | - fail("MissingArgumentException not caught."); |
228 | | - } catch (final MissingArgumentException expected) { |
229 | | - } |
| 222 | + assertThrows(MissingArgumentException.class, () -> new PosixParser().parse(options, args)); |
230 | 223 | } |
231 | 224 |
|
232 | 225 | @Test |
@@ -279,21 +272,10 @@ public void test13935() throws Exception { |
279 | 272 |
|
280 | 273 | final CommandLineParser parser = new PosixParser(); |
281 | 274 |
|
282 | | - String[] args = {}; |
283 | | - try { |
284 | | - parser.parse(opts, args); |
285 | | - fail("Expected ParseException"); |
286 | | - } catch (final ParseException expected) { |
287 | | - } |
288 | | - |
289 | | - args = new String[] {"-s"}; |
290 | | - try { |
291 | | - parser.parse(opts, args); |
292 | | - fail("Expected ParseException"); |
293 | | - } catch (final ParseException expected) { |
294 | | - } |
| 275 | + assertThrows(ParseException.class, () -> parser.parse(opts, ArrayUtils.EMPTY_STRING_ARRAY)); |
| 276 | + assertThrows(ParseException.class, () -> parser.parse(opts, new String[] {"-s"})); |
295 | 277 |
|
296 | | - args = new String[] {"-s", "-l"}; |
| 278 | + String[] args = {"-s", "-l"}; |
297 | 279 | CommandLine line = parser.parse(opts, args); |
298 | 280 | assertNotNull(line); |
299 | 281 |
|
|
0 commit comments