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