View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.datadictionary.validation.fieldlevel;
17  
18  import org.junit.Test;
19  import org.kuali.test.KNSTestCase;
20  import org.kuali.test.KNSWithTestSpringContext;
21  
22  
23  @KNSWithTestSpringContext
24  public class FloatingPointValidationPatternTest extends KNSTestCase {
25      FloatingPointValidationPattern pattern;
26  
27      @Override
28      public final void setUp() throws Exception {
29          super.setUp();
30  
31          pattern = new FloatingPointValidationPattern();
32      }
33  
34  
35      @Test public final void testDefaultAllows_positive1() {
36          assertTrue(pattern.matches(".1"));
37      }
38  
39      @Test public final void testDefaultAllows_positive2() {
40          assertTrue(pattern.matches("0.1"));
41      }
42  
43      @Test public final void testDefaultAllows_positive3() {
44          assertTrue(pattern.matches("1.1"));
45      }
46  
47      @Test public final void testDefaultAllows_positive4() {
48          assertTrue(pattern.matches("1"));
49      }
50  
51      @Test public final void testDefaultAllows_positive5() {
52          assertTrue(pattern.matches("1.0"));
53      }
54  
55  
56      @Test public final void testDefaultAllows_negative1() {
57          assertFalse(pattern.matches("-.1"));
58      }
59  
60      @Test public final void testDefaultAllows_negative2() {
61          assertFalse(pattern.matches("-0.1"));
62      }
63  
64      @Test public final void testDefaultAllows_negative3() {
65          assertFalse(pattern.matches("-1.1"));
66      }
67  
68      @Test public final void testDefaultAllows_negative4() {
69          assertFalse(pattern.matches("-1"));
70      }
71  
72      @Test public final void testDefaultAllows_negative5() {
73          assertFalse(pattern.matches("-1.0"));
74      }
75  
76  
77      @Test public final void testDefaultAllows_invalid1() {
78          assertFalse(pattern.matches("-."));
79      }
80  
81      @Test public final void testDefaultAllows_invalid2() {
82          assertFalse(pattern.matches("1."));
83      }
84  
85      @Test public final void testDefaultAllows_invalid3() {
86          assertFalse(pattern.matches("-1."));
87      }
88  
89  
90      @Test public final void testAllowNegative_positive1() {
91          pattern.setAllowNegative(true);
92  
93          assertTrue(pattern.matches(".1"));
94      }
95  
96      @Test public final void testAllowNegative_positive2() {
97          pattern.setAllowNegative(true);
98  
99          assertTrue(pattern.matches("0.1"));
100     }
101 
102     @Test public final void testAllowNegative_positive3() {
103         pattern.setAllowNegative(true);
104 
105         assertTrue(pattern.matches("1.1"));
106     }
107 
108     @Test public final void testAllowNegative_positive4() {
109         pattern.setAllowNegative(true);
110 
111         assertTrue(pattern.matches("1"));
112     }
113 
114     @Test public final void testAllowNegative_positive5() {
115         pattern.setAllowNegative(true);
116 
117         assertTrue(pattern.matches("1.0"));
118     }
119 
120 
121     @Test public final void testAllowNegative_negative1() {
122         pattern.setAllowNegative(true);
123 
124         assertTrue(pattern.matches("-.1"));
125     }
126 
127     @Test public final void testAllowNegative_negative2() {
128         pattern.setAllowNegative(true);
129 
130         assertTrue(pattern.matches("-0.1"));
131     }
132 
133     @Test public final void testAllowNegative_negative3() {
134         pattern.setAllowNegative(true);
135 
136         assertTrue(pattern.matches("-1.1"));
137     }
138 
139     @Test public final void testAllowNegative_negative4() {
140         pattern.setAllowNegative(true);
141 
142         assertTrue(pattern.matches("-1"));
143     }
144 
145     @Test public final void testAllowNegative_negative5() {
146         pattern.setAllowNegative(true);
147 
148         assertTrue(pattern.matches("-1.0"));
149     }
150 
151 
152     @Test public final void testAllowNegative_invalid1() {
153         pattern.setAllowNegative(true);
154 
155         assertFalse(pattern.matches("-."));
156     }
157 
158     @Test public final void testAllowNegative_invalid2() {
159         pattern.setAllowNegative(true);
160 
161         assertFalse(pattern.matches("1."));
162     }
163 
164     @Test public final void testAllowNegative_invalid3() {
165         pattern.setAllowNegative(true);
166 
167         assertFalse(pattern.matches("-1."));
168     }
169 }