Skip to content

Commit

Permalink
Use assertThrows()
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Oct 19, 2024
1 parent 1b7e71f commit 3896533
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
Expand Down Expand Up @@ -104,13 +102,9 @@ public void testObjectPattern() throws Exception {
public void testRequiredOption() throws Exception {
final Options options = PatternOptionBuilder.parsePattern("!n%m%");
final CommandLineParser parser = new PosixParser();
try {
parser.parse(options, new String[] {""});
fail("MissingOptionException wasn't thrown");
} catch (final MissingOptionException e) {
assertEquals(1, e.getMissingOptions().size());
assertTrue(e.getMissingOptions().contains("n"));
}
final MissingOptionException e = assertThrows(MissingOptionException.class, () -> parser.parse(options, new String[] { "" }));
assertEquals(1, e.getMissingOptions().size());
assertTrue(e.getMissingOptions().contains("n"));
}

@Test
Expand Down

0 comments on commit 3896533

Please sign in to comment.