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