You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dw...@apache.org on 2002/03/30 05:32:14 UTC
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator TestValidator.java
dwinterfeldt 02/03/29 20:32:14
Modified: validator/src/test/org/apache/commons/validator
TestValidator.java
Log:
Added new validation methods for the new unit tests.
Revision Changes Path
1.3 +90 -0 jakarta-commons/validator/src/test/org/apache/commons/validator/TestValidator.java
Index: TestValidator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TestValidator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestValidator.java 17 Mar 2002 00:27:35 -0000 1.2
+++ TestValidator.java 30 Mar 2002 04:32:14 -0000 1.3
@@ -1,4 +1,9 @@
/*
+ * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TestValidator.java,v 1.3 2002/03/30 04:32:14 dwinterfeldt Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/03/30 04:32:14 $
+ *
+ * ====================================================================
*
* The Apache Software License, Version 1.1
*
@@ -62,6 +67,7 @@
* unit tests.</p>
*
* @author David Winterfeldt
+ * @version $Revision: 1.3 $ $Date: 2002/03/30 04:32:14 $
*/
public class TestValidator {
@@ -79,5 +85,89 @@
return !GenericValidator.isBlankOrNull(value);
}
+
+ /**
+ * Checks if the field can be successfully converted to a <code>byte</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @return boolean If the field can be successfully converted
+ * to a <code>byte</code> <code>true</code> is returned.
+ * Otherwise <code>false</code>.
+ */
+ public static boolean validateByte(Object bean, Field field) {
+ String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isByte(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a <code>short</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @return boolean If the field can be successfully converted
+ * to a <code>short</code> <code>true</code> is returned.
+ * Otherwise <code>false</code>.
+ */
+ public static boolean validateShort(Object bean, Field field) {
+ String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isShort(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a <code>int</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @return boolean If the field can be successfully converted
+ * to a <code>int</code> <code>true</code> is returned.
+ * Otherwise <code>false</code>.
+ */
+ public static boolean validateInt(Object bean, Field field) {
+ String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isInt(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a <code>long</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @return boolean If the field can be successfully converted
+ * to a <code>long</code> <code>true</code> is returned.
+ * Otherwise <code>false</code>.
+ */
+ public static boolean validateLong(Object bean, Field field) {
+ String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isLong(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a <code>float</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @return boolean If the field can be successfully converted
+ * to a <code>float</code> <code>true</code> is returned.
+ * Otherwise <code>false</code>.
+ */
+ public static boolean validateFloat(Object bean, Field field) {
+ String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isFloat(value);
+ }
+ /**
+ * Checks if the field can be successfully converted to a <code>double</code>.
+ *
+ * @param value The value validation is being performed on.
+ * @return boolean If the field can be successfully converted
+ * to a <code>double</code> <code>true</code> is returned.
+ * Otherwise <code>false</code>.
+ */
+ public static boolean validateDouble(Object bean, Field field) {
+ String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isDouble(value);
+ }
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>