Skip to content

Commit

Permalink
Simplified test
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg committed Dec 17, 2023
1 parent 086d7ba commit a73c132
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/test/java/com/beust/jcommander/MethodSetterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,21 @@ public void setHost(String host) {
Assert.assertTrue(passed, "Should have thrown an exception");
}

@Test(expectedExceptions = ParameterException.class)
public void setterThatThrowsKeepsOriginalException() {
class Arg {
@Parameter(names = "--host")
public void setHost(String host) {
throw new IllegalArgumentException("Illegal host");
}
}
boolean passed = false;
try {
JCommander.newBuilder().addObject(new Arg()).build().parse("--host", "host");
} catch(ParameterException ex) {
} catch (ParameterException ex) {
Assert.assertEquals(ex.getCause().getClass(), IllegalArgumentException.class);
Assert.assertEquals(ex.getCause().getMessage(), "Illegal host");
passed = true;
throw ex;
}
Assert.assertTrue(passed, "Should have thrown an exception");
}

public void getterReturningNonString() {
Expand Down

0 comments on commit a73c132

Please sign in to comment.