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