001: /*
002: * Copyright 2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.datadictionary.validation.fieldlevel;
017:
018: import org.junit.Test;
019: import org.kuali.test.KNSTestBase;
020:
021: public class FixedPointValidationPatternTest extends KNSTestBase {
022: // Unlike its superclass, FixedPointValidationPattern does not use Spring.
023: FixedPointValidationPattern pattern;
024:
025: @Override
026: @Test
027: public final void setUp() throws Exception {
028: super .setUp();
029:
030: pattern = new FixedPointValidationPattern();
031: pattern.setPrecision(2);
032: pattern.setScale(1);
033: }
034:
035: @Test
036: public final void testDefaultAllows_empty() {
037: assertFalse(pattern.matches(""));
038: }
039:
040: @Test
041: public final void testDefaultAllows_positive1() {
042: assertTrue(pattern.matches(".1"));
043: }
044:
045: @Test
046: public final void testDefaultAllows_positive2() {
047: assertTrue(pattern.matches("0.1"));
048: }
049:
050: @Test
051: public final void testDefaultAllows_positive3() {
052: assertTrue(pattern.matches("1.1"));
053: }
054:
055: @Test
056: public final void testDefaultAllows_positive4() {
057: assertTrue(pattern.matches("1"));
058: }
059:
060: @Test
061: public final void testDefaultAllows_positive5() {
062: assertTrue(pattern.matches("1.0"));
063: }
064:
065: @Test
066: public final void testDefaultAllows_negative1() {
067: assertFalse(pattern.matches("-.1"));
068: }
069:
070: @Test
071: public final void testDefaultAllows_negative2() {
072: assertFalse(pattern.matches("-0.1"));
073: }
074:
075: @Test
076: public final void testDefaultAllows_negative3() {
077: assertFalse(pattern.matches("-1.1"));
078: }
079:
080: @Test
081: public final void testDefaultAllows_negative4() {
082: assertFalse(pattern.matches("-1"));
083: }
084:
085: @Test
086: public final void testDefaultAllows_negative5() {
087: assertFalse(pattern.matches("-1.0"));
088: }
089:
090: @Test
091: public final void testDefaultAllows_invalid1() {
092: assertFalse(pattern.matches("-."));
093: }
094:
095: @Test
096: public final void testDefaultAllows_invalid2() {
097: assertFalse(pattern.matches("1."));
098: }
099:
100: @Test
101: public final void testDefaultAllows_invalid3() {
102: assertFalse(pattern.matches("-1."));
103: }
104:
105: @Test
106: public final void testDefaultAllows_invalid4() {
107: assertFalse(pattern.matches("12."));
108: }
109:
110: @Test
111: public final void testDefaultAllows_invalid5() {
112: assertFalse(pattern.matches("1245678901234567890123.23"));
113: }
114:
115: @Test
116: public final void testDefaultAllows_invalid6() {
117: assertFalse(pattern.matches("123"));
118: }
119:
120: @Test
121: public final void testAllowNegative_positive1() {
122: assertTrue(pattern.matches(".1"));
123: }
124:
125: @Test
126: public final void testAllowNegative_positive2() {
127: pattern.setAllowNegative(true);
128:
129: assertTrue(pattern.matches("0.1"));
130: }
131:
132: @Test
133: public final void testAllowNegative_positive3() {
134: pattern.setAllowNegative(true);
135:
136: assertTrue(pattern.matches("1.1"));
137: }
138:
139: @Test
140: public final void testAllowNegative_positive4() {
141: pattern.setAllowNegative(true);
142:
143: assertTrue(pattern.matches("1"));
144: }
145:
146: @Test
147: public final void testAllowNegative_positive5() {
148: pattern.setAllowNegative(true);
149:
150: assertTrue(pattern.matches("1.0"));
151: }
152:
153: @Test
154: public final void testAllowNegative_negative1() {
155: pattern.setAllowNegative(true);
156:
157: assertTrue(pattern.matches("-.1"));
158: }
159:
160: @Test
161: public final void testAllowNegative_negative2() {
162: pattern.setAllowNegative(true);
163:
164: assertTrue(pattern.matches("-0.1"));
165: }
166:
167: @Test
168: public final void testAllowNegative_negative3() {
169: pattern.setAllowNegative(true);
170:
171: assertTrue(pattern.matches("-1.1"));
172: }
173:
174: @Test
175: public final void testAllowNegative_negative4() {
176: pattern.setAllowNegative(true);
177:
178: assertTrue(pattern.matches("-1"));
179: }
180:
181: @Test
182: public final void testAllowNegative_negative5() {
183: pattern.setAllowNegative(true);
184:
185: assertTrue(pattern.matches("-1.0"));
186: }
187:
188: @Test
189: public final void testAllowNegative_invalid1() {
190: pattern.setAllowNegative(true);
191:
192: assertFalse(pattern.matches("-."));
193: }
194:
195: @Test
196: public final void testAllowNegative_invalid2() {
197: pattern.setAllowNegative(true);
198:
199: assertFalse(pattern.matches("1."));
200: }
201:
202: @Test
203: public final void testAllowNegative_invalid3() {
204: pattern.setAllowNegative(true);
205:
206: assertFalse(pattern.matches("-1."));
207: }
208:
209: @Test
210: public final void testAllowNegative_invalid4() {
211: pattern.setAllowNegative(true);
212:
213: assertFalse(pattern.matches("-12."));
214: }
215:
216: @Test
217: public final void testAllowNegative_invalid5() {
218: pattern.setAllowNegative(true);
219:
220: assertFalse(pattern.matches("-1.23"));
221: }
222:
223: @Test
224: public final void testAllowNegative_invalid6() {
225: pattern.setAllowNegative(true);
226:
227: assertFalse(pattern.matches("123."));
228: }
229:
230: @Test
231: public final void testAllowNegative_invalid7() {
232: pattern.setAllowNegative(true);
233:
234: assertFalse(pattern.matches(".123"));
235: }
236:
237: }
|