1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.commons.validator;
23
24 import org.apache.commons.validator.util.ValidatorUtils;
25
26 /***
27 * Contains validation methods for different unit tests.
28 */
29 public class TestTypeValidator {
30
31 /***
32 * Checks if the field can be successfully converted to a <code>byte</code>.
33 *
34 * @param value The value validation is being performed on.
35 * @return boolean If the field can be successfully converted
36 * to a <code>byte</code> <code>true</code> is returned.
37 * Otherwise <code>false</code>.
38 */
39 public static Byte validateByte(Object bean, Field field) {
40 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
41
42 return GenericTypeValidator.formatByte(value);
43 }
44
45 /***
46 * Checks if the field can be successfully converted to a <code>short</code>.
47 *
48 * @param value The value validation is being performed on.
49 * @return boolean If the field can be successfully converted
50 * to a <code>short</code> <code>true</code> is returned.
51 * Otherwise <code>false</code>.
52 */
53 public static Short validateShort(Object bean, Field field) {
54 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
55
56 return GenericTypeValidator.formatShort(value);
57 }
58
59 /***
60 * Checks if the field can be successfully converted to a <code>int</code>.
61 *
62 * @param value The value validation is being performed on.
63 * @return boolean If the field can be successfully converted
64 * to a <code>int</code> <code>true</code> is returned.
65 * Otherwise <code>false</code>.
66 */
67 public static Integer validateInt(Object bean, Field field) {
68 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
69
70 return GenericTypeValidator.formatInt(value);
71 }
72
73 /***
74 * Checks if the field can be successfully converted to a <code>long</code>.
75 *
76 * @param value The value validation is being performed on.
77 * @return boolean If the field can be successfully converted
78 * to a <code>long</code> <code>true</code> is returned.
79 * Otherwise <code>false</code>.
80 */
81 public static Long validateLong(Object bean, Field field) {
82 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
83
84 return GenericTypeValidator.formatLong(value);
85 }
86
87 /***
88 * Checks if the field can be successfully converted to a <code>float</code>.
89 *
90 * @param value The value validation is being performed on.
91 * @return boolean If the field can be successfully converted
92 * to a <code>float</code> <code>true</code> is returned.
93 * Otherwise <code>false</code>.
94 */
95 public static Float validateFloat(Object bean, Field field) {
96 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
97
98 return GenericTypeValidator.formatFloat(value);
99 }
100
101 /***
102 * Checks if the field can be successfully converted to a <code>double</code>.
103 *
104 * @param value The value validation is being performed on.
105 * @return boolean If the field can be successfully converted
106 * to a <code>double</code> <code>true</code> is returned.
107 * Otherwise <code>false</code>.
108 */
109 public static Double validateDouble(Object bean, Field field) {
110 String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
111
112 return GenericTypeValidator.formatDouble(value);
113 }
114
115 }