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