changeset 847:eac857745b29

PortValidator improvements
author Devel 2
date Tue, 23 Jan 2018 13:43:26 +0100
parents c6bd0e721da3
children adce7f619e22
files stress-tester/src/main/java/com/passus/st/validation/PortValidator.java stress-tester/src/test/java/com/passus/st/validation/PortValidatorTest.java
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/validation/PortValidator.java	Tue Jan 23 13:30:36 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/validation/PortValidator.java	Tue Jan 23 13:43:26 2018 +0100
@@ -11,7 +11,8 @@
 
     @Override
     public boolean supports(Class<?> clazz) {
-        return Number.class.isAssignableFrom(clazz)
+        return Integer.class.equals(clazz)
+                || Long.class.equals(clazz)
                 || String.class.isAssignableFrom(clazz);
     }
 
@@ -23,10 +24,13 @@
             }
 
             int targetInt;
-            if (target instanceof Number) {
-                targetInt = Type.INTEGER.convert(((Number) target).intValue());
+            if (target instanceof Integer || target instanceof Long) {
+                targetInt = Type.INTEGER.convert(target);
+            } else if (target instanceof String) {
+                targetInt = Integer.parseInt((String) target);
             } else {
-                targetInt = Integer.parseInt(target.toString());
+                errors.reject("Invalid port.");
+                return;
             }
 
             if (!PortRange.RANGE_FULL.inRange(targetInt)) {
--- a/stress-tester/src/test/java/com/passus/st/validation/PortValidatorTest.java	Tue Jan 23 13:30:36 2018 +0100
+++ b/stress-tester/src/test/java/com/passus/st/validation/PortValidatorTest.java	Tue Jan 23 13:43:26 2018 +0100
@@ -19,9 +19,12 @@
         return new Object[][]{
                 {null, null},
                 {1, null},
+                {1L, null},
                 {"1", null},
                 {0, null},
                 {-1, "Invalid port. Value should be in range 0-65535."},
+                {1.0d, "Invalid port."},
+                {1.0f, "Invalid port."},
                 {"700000", "Invalid port. Value should be in range 0-65535."},
                 {"a", "Invalid port."}
         };