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