diff options
author | Cedric Beust <cedric@beust.com> | 2012-07-06 23:26:16 -0700 |
---|---|---|
committer | Cedric Beust <cedric@beust.com> | 2012-07-06 23:26:16 -0700 |
commit | e0c1cdc5cea32d7551cf92069adfd529fc48a756 (patch) | |
tree | 0fdbe7704a71c613459bbbddc89af88ec8135ef6 /src/test/java/com/beust | |
parent | a85606887e78c48622d46032b39887542496f2c8 (diff) | |
download | jcommander-e0c1cdc5cea32d7551cf92069adfd529fc48a756.tar.gz |
If a setter throws ParameterException, don't wrap it into another ParameterException.
Diffstat (limited to 'src/test/java/com/beust')
-rw-r--r-- | src/test/java/com/beust/jcommander/JCommanderTest.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/test/java/com/beust/jcommander/JCommanderTest.java b/src/test/java/com/beust/jcommander/JCommanderTest.java index 9dba74d..8b1e761 100644 --- a/src/test/java/com/beust/jcommander/JCommanderTest.java +++ b/src/test/java/com/beust/jcommander/JCommanderTest.java @@ -837,9 +837,26 @@ public class JCommanderTest { Assert.assertTrue(arg.help); } + public void setterThatThrows() { + class Arg { + @Parameter(names = "--host") + public void setHost(String host) { + throw new ParameterException("Illegal host"); + } + } + boolean passed = false; + try { + new JCommander(new Arg(), new String[] { "--host", "host" }); + } catch(ParameterException ex) { + Assert.assertEquals(ex.getCause(), null); + passed = true; + } + Assert.assertTrue(passed, "Should have thrown an exception"); + } + @Test(enabled = false) public static void main(String[] args) throws Exception { - new JCommanderTest().verifyHelp(); + new JCommanderTest().setterThatThrows(); // class A { // @Parameter(names = "-short", required = true) // List<String> parameters; |