diff options
author | Igor Murashkin <iam@google.com> | 2016-03-24 14:21:34 -0700 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2016-03-24 14:21:57 -0700 |
commit | 7f95581d269e0815eab16115f0e36c0ee325dc88 (patch) | |
tree | f1aa3cbaef213c6d2693df6d0ae4d449cc3e6815 /src/test/java/com/beust/jcommander/PositiveIntegerTest.java | |
parent | b3994367e22d0ce3670ff9fb693a4f2939ef5d58 (diff) | |
parent | 5321f6ff3251784760f79982b1a720e3607c5003 (diff) | |
download | platform_external_jcommander-7f95581d269e0815eab16115f0e36c0ee325dc88.tar.gz platform_external_jcommander-7f95581d269e0815eab16115f0e36c0ee325dc88.tar.bz2 platform_external_jcommander-7f95581d269e0815eab16115f0e36c0ee325dc88.zip |
Merge remote-tracking branch 'goog/master' into nyc-dev
Bug: 27552463
Change-Id: Icaacbb9acf1454b39974d319d30023aea6fea5f6
Diffstat (limited to 'src/test/java/com/beust/jcommander/PositiveIntegerTest.java')
-rw-r--r-- | src/test/java/com/beust/jcommander/PositiveIntegerTest.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/java/com/beust/jcommander/PositiveIntegerTest.java b/src/test/java/com/beust/jcommander/PositiveIntegerTest.java new file mode 100644 index 0000000..ec7d273 --- /dev/null +++ b/src/test/java/com/beust/jcommander/PositiveIntegerTest.java @@ -0,0 +1,65 @@ +package com.beust.jcommander; + +import com.beust.jcommander.validators.PositiveInteger; + +import org.testng.annotations.Test; + +public class PositiveIntegerTest { + + @Test + public void validateTest() { + class Arg { + @Parameter(names = { "-p", "--port" }, description = "Shows help", validateWith = PositiveInteger.class) + private int port = 0; + } + Arg arg = new Arg(); + JCommander jc = new JCommander(arg); + jc.parse(new String[] { "-p", "8080" }); + + } + + @Test(expectedExceptions = ParameterException.class) + public void validateTest2() { + class Arg { + @Parameter(names = { "-p", "--port" }, description = "Shows help", validateWith = PositiveInteger.class) + private int port = 0; + } + Arg arg = new Arg(); + JCommander jc = new JCommander(arg); + jc.parse(new String[] { "-p", "" }); + } + + @Test(expectedExceptions = ParameterException.class) + public void validateTest3() { + class Arg { + @Parameter(names = { "-p", "--port" }, description = "Shows help", validateWith = PositiveInteger.class) + private int port = 0; + } + Arg arg = new Arg(); + JCommander jc = new JCommander(arg); + jc.parse(new String[] { "-p", "-1" }); + } + + @Test(expectedExceptions = ParameterException.class) + public void validateTest4() { + class Arg { + @Parameter(names = { "-p", "--port" }, description = "Port Number", validateWith = PositiveInteger.class) + private int port = 0; + } + Arg arg = new Arg(); + JCommander jc = new JCommander(arg); + jc.parse(new String[] { "-p", "abc" }); + } + + @Test(expectedExceptions = ParameterException.class) + public void validateTest5() { + class Arg { + @Parameter(names = { "-p", "--port" }, description = "Port Number", validateWith = PositiveInteger.class) + private int port = 0; + } + + Arg arg = new Arg(); + JCommander jc = new JCommander(arg); + jc.parse(new String[] { "--port", " " }); + } +}
\ No newline at end of file |