1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validation.fieldlevel;
17
18 import org.junit.Test;
19 import org.kuali.rice.kns.datadictionary.validation.fieldlevel.FloatingPointValidationPattern;
20 import org.kuali.rice.krad.test.KRADTestCase;
21
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24
25
26
27
28
29
30
31
32 public class FloatingPointValidationPatternTest extends KRADTestCase {
33 FloatingPointValidationPattern pattern;
34
35 @Override
36 public final void setUp() throws Exception {
37 super.setUp();
38
39 pattern = new FloatingPointValidationPattern();
40 }
41
42
43 @Test public final void testDefaultAllows_positive1() {
44 assertTrue(pattern.matches(".1"));
45 }
46
47 @Test public final void testDefaultAllows_positive2() {
48 assertTrue(pattern.matches("0.1"));
49 }
50
51 @Test public final void testDefaultAllows_positive3() {
52 assertTrue(pattern.matches("1.1"));
53 }
54
55 @Test public final void testDefaultAllows_positive4() {
56 assertTrue(pattern.matches("1"));
57 }
58
59 @Test public final void testDefaultAllows_positive5() {
60 assertTrue(pattern.matches("1.0"));
61 }
62
63
64 @Test public final void testDefaultAllows_negative1() {
65 assertFalse(pattern.matches("-.1"));
66 }
67
68 @Test public final void testDefaultAllows_negative2() {
69 assertFalse(pattern.matches("-0.1"));
70 }
71
72 @Test public final void testDefaultAllows_negative3() {
73 assertFalse(pattern.matches("-1.1"));
74 }
75
76 @Test public final void testDefaultAllows_negative4() {
77 assertFalse(pattern.matches("-1"));
78 }
79
80 @Test public final void testDefaultAllows_negative5() {
81 assertFalse(pattern.matches("-1.0"));
82 }
83
84
85 @Test public final void testDefaultAllows_invalid1() {
86 assertFalse(pattern.matches("-."));
87 }
88
89 @Test public final void testDefaultAllows_invalid2() {
90 assertFalse(pattern.matches("1."));
91 }
92
93 @Test public final void testDefaultAllows_invalid3() {
94 assertFalse(pattern.matches("-1."));
95 }
96
97
98 @Test public final void testAllowNegative_positive1() {
99 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 }