1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.datadictionary.validation.fieldlevel;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.kns.datadictionary.validation.ValidationPattern;
21 import org.kuali.rice.test.BaseRiceTestCase;
22
23 public class FixedPointValidationPatternTest extends BaseRiceTestCase {
24
25 FixedPointValidationPattern pattern;
26
27 @Before
28 public final void setUp() throws Exception {
29
30 pattern = new FixedPointValidationPattern();
31 pattern.setPrecision(2);
32 pattern.setScale(1);
33 }
34
35
36 @Test public final void testDefaultAllows_empty() {
37 assertFalse(pattern.matches(""));
38 }
39
40 @Test public final void testDefaultAllows_positive1() {
41 assertTrue(pattern.matches(".1"));
42 }
43
44 @Test public final void testDefaultAllows_positive2() {
45 assertTrue(pattern.matches("0.1"));
46 }
47
48 @Test public final void testDefaultAllows_positive3() {
49 assertTrue(pattern.matches("1.1"));
50 }
51
52 @Test public final void testDefaultAllows_positive4() {
53 assertTrue(pattern.matches("1"));
54 }
55
56 @Test public final void testDefaultAllows_positive5() {
57 assertTrue(pattern.matches("1.0"));
58 }
59
60
61 @Test public final void testDefaultAllows_negative1() {
62 assertFalse(pattern.matches("-.1"));
63 }
64
65 @Test public final void testDefaultAllows_negative2() {
66 assertFalse(pattern.matches("-0.1"));
67 }
68
69 @Test public final void testDefaultAllows_negative3() {
70 assertFalse(pattern.matches("-1.1"));
71 }
72
73 @Test public final void testDefaultAllows_negative4() {
74 assertFalse(pattern.matches("-1"));
75 }
76
77 @Test public final void testDefaultAllows_negative5() {
78 assertFalse(pattern.matches("-1.0"));
79 }
80
81
82 @Test public final void testDefaultAllows_invalid1() {
83 assertFalse(pattern.matches("-."));
84 }
85
86 @Test public final void testDefaultAllows_invalid2() {
87 assertFalse(pattern.matches("1."));
88 }
89
90 @Test public final void testDefaultAllows_invalid3() {
91 assertFalse(pattern.matches("-1."));
92 }
93
94 @Test public final void testDefaultAllows_invalid4() {
95 assertFalse(pattern.matches("12."));
96 }
97
98 @Test public final void testDefaultAllows_invalid5() {
99 assertFalse(pattern.matches("1245678901234567890123.23"));
100 }
101
102 @Test public final void testDefaultAllows_invalid6() {
103 assertFalse(pattern.matches("123"));
104 }
105
106 @Test public final void testAllowNegative_positive1() {
107 assertTrue(pattern.matches(".1"));
108 }
109
110 @Test public final void testAllowNegative_positive2() {
111 pattern.setAllowNegative(true);
112
113 assertTrue(pattern.matches("0.1"));
114 }
115
116 @Test public final void testAllowNegative_positive3() {
117 pattern.setAllowNegative(true);
118
119 assertTrue(pattern.matches("1.1"));
120 }
121
122 @Test public final void testAllowNegative_positive4() {
123 pattern.setAllowNegative(true);
124
125 assertTrue(pattern.matches("1"));
126 }
127
128 @Test public final void testAllowNegative_positive5() {
129 pattern.setAllowNegative(true);
130
131 assertTrue(pattern.matches("1.0"));
132 }
133
134
135 @Test public final void testAllowNegative_negative1() {
136 pattern.setAllowNegative(true);
137
138 assertTrue(pattern.matches("-.1"));
139 }
140
141 @Test public final void testAllowNegative_negative2() {
142 pattern.setAllowNegative(true);
143
144 assertTrue(pattern.matches("-0.1"));
145 }
146
147 @Test public final void testAllowNegative_negative3() {
148 pattern.setAllowNegative(true);
149
150 assertTrue(pattern.matches("-1.1"));
151 }
152
153 @Test public final void testAllowNegative_negative4() {
154 pattern.setAllowNegative(true);
155
156 assertTrue(pattern.matches("-1"));
157 }
158
159 @Test public final void testAllowNegative_negative5() {
160 pattern.setAllowNegative(true);
161
162 assertTrue(pattern.matches("-1.0"));
163 }
164
165
166 @Test public final void testAllowNegative_invalid1() {
167 pattern.setAllowNegative(true);
168
169 assertFalse(pattern.matches("-."));
170 }
171
172 @Test public final void testAllowNegative_invalid2() {
173 pattern.setAllowNegative(true);
174
175 assertFalse(pattern.matches("1."));
176 }
177
178 @Test public final void testAllowNegative_invalid3() {
179 pattern.setAllowNegative(true);
180
181 assertFalse(pattern.matches("-1."));
182 }
183
184 @Test public final void testAllowNegative_invalid4() {
185 pattern.setAllowNegative(true);
186
187 assertFalse(pattern.matches("-12."));
188 }
189
190 @Test public final void testAllowNegative_invalid5() {
191 pattern.setAllowNegative(true);
192
193 assertFalse(pattern.matches("-1.23"));
194 }
195
196 @Test public final void testAllowNegative_invalid6() {
197 pattern.setAllowNegative(true);
198
199 assertFalse(pattern.matches("123."));
200 }
201
202 @Test public final void testAllowNegative_invalid7() {
203 pattern.setAllowNegative(true);
204
205 assertFalse(pattern.matches(".123"));
206 }
207
208 @Test(expected=ValidationPattern.ValidationPatternException.class)
209 public final void testZero_Percision_And_Scale_invalid8() {
210
211 pattern.setPrecision(0);
212 pattern.setScale(0);
213 pattern.completeValidation();
214 }
215
216 @Test(expected=ValidationPattern.ValidationPatternException.class)
217 public final void testPrecision_Less_Than_Scale_invalid9() {
218 pattern.setPrecision(1);
219 pattern.setScale(3);
220 pattern.completeValidation();
221 }
222
223 @Test(expected=ValidationPattern.ValidationPatternException.class)
224 public final void testPrecision_And_Scale_Negative_invalid10() {
225 pattern.setPrecision(-3);
226 pattern.setScale(-1);
227 pattern.completeValidation();
228 }
229
230 }