001: /*
002: * Copyright 2005-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: import org.kuali.test.KNSWithTestSpringContext;
021:
022: @KNSWithTestSpringContext
023: public class FloatingPointValidationPatternTest extends KNSTestBase {
024: FloatingPointValidationPattern pattern;
025:
026: @Override
027: @Test
028: public final void setUp() throws Exception {
029: super .setUp();
030:
031: pattern = new FloatingPointValidationPattern();
032: }
033:
034: @Test
035: public final void testDefaultAllows_positive1() {
036: assertTrue(pattern.matches(".1"));
037: }
038:
039: @Test
040: public final void testDefaultAllows_positive2() {
041: assertTrue(pattern.matches("0.1"));
042: }
043:
044: @Test
045: public final void testDefaultAllows_positive3() {
046: assertTrue(pattern.matches("1.1"));
047: }
048:
049: @Test
050: public final void testDefaultAllows_positive4() {
051: assertTrue(pattern.matches("1"));
052: }
053:
054: @Test
055: public final void testDefaultAllows_positive5() {
056: assertTrue(pattern.matches("1.0"));
057: }
058:
059: @Test
060: public final void testDefaultAllows_negative1() {
061: assertFalse(pattern.matches("-.1"));
062: }
063:
064: @Test
065: public final void testDefaultAllows_negative2() {
066: assertFalse(pattern.matches("-0.1"));
067: }
068:
069: @Test
070: public final void testDefaultAllows_negative3() {
071: assertFalse(pattern.matches("-1.1"));
072: }
073:
074: @Test
075: public final void testDefaultAllows_negative4() {
076: assertFalse(pattern.matches("-1"));
077: }
078:
079: @Test
080: public final void testDefaultAllows_negative5() {
081: assertFalse(pattern.matches("-1.0"));
082: }
083:
084: @Test
085: public final void testDefaultAllows_invalid1() {
086: assertFalse(pattern.matches("-."));
087: }
088:
089: @Test
090: public final void testDefaultAllows_invalid2() {
091: assertFalse(pattern.matches("1."));
092: }
093:
094: @Test
095: public final void testDefaultAllows_invalid3() {
096: assertFalse(pattern.matches("-1."));
097: }
098:
099: @Test
100: public final void testAllowNegative_positive1() {
101: pattern.setAllowNegative(true);
102:
103: assertTrue(pattern.matches(".1"));
104: }
105:
106: @Test
107: public final void testAllowNegative_positive2() {
108: pattern.setAllowNegative(true);
109:
110: assertTrue(pattern.matches("0.1"));
111: }
112:
113: @Test
114: public final void testAllowNegative_positive3() {
115: pattern.setAllowNegative(true);
116:
117: assertTrue(pattern.matches("1.1"));
118: }
119:
120: @Test
121: public final void testAllowNegative_positive4() {
122: pattern.setAllowNegative(true);
123:
124: assertTrue(pattern.matches("1"));
125: }
126:
127: @Test
128: public final void testAllowNegative_positive5() {
129: pattern.setAllowNegative(true);
130:
131: assertTrue(pattern.matches("1.0"));
132: }
133:
134: @Test
135: public final void testAllowNegative_negative1() {
136: pattern.setAllowNegative(true);
137:
138: assertTrue(pattern.matches("-.1"));
139: }
140:
141: @Test
142: public final void testAllowNegative_negative2() {
143: pattern.setAllowNegative(true);
144:
145: assertTrue(pattern.matches("-0.1"));
146: }
147:
148: @Test
149: public final void testAllowNegative_negative3() {
150: pattern.setAllowNegative(true);
151:
152: assertTrue(pattern.matches("-1.1"));
153: }
154:
155: @Test
156: public final void testAllowNegative_negative4() {
157: pattern.setAllowNegative(true);
158:
159: assertTrue(pattern.matches("-1"));
160: }
161:
162: @Test
163: public final void testAllowNegative_negative5() {
164: pattern.setAllowNegative(true);
165:
166: assertTrue(pattern.matches("-1.0"));
167: }
168:
169: @Test
170: public final void testAllowNegative_invalid1() {
171: pattern.setAllowNegative(true);
172:
173: assertFalse(pattern.matches("-."));
174: }
175:
176: @Test
177: public final void testAllowNegative_invalid2() {
178: pattern.setAllowNegative(true);
179:
180: assertFalse(pattern.matches("1."));
181: }
182:
183: @Test
184: public final void testAllowNegative_invalid3() {
185: pattern.setAllowNegative(true);
186:
187: assertFalse(pattern.matches("-1."));
188: }
189: }
|