1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validation.charlevel;
17
18 import org.junit.Test;
19 import org.kuali.rice.kns.datadictionary.validation.charlevel.RegexValidationPattern;
20 import org.kuali.rice.test.BaseRiceTestCase;
21
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24
25
26
27
28
29
30
31 public class RegexValidationPatternTest extends BaseRiceTestCase {
32 private RegexValidationPattern regexValidationPattern;
33
34 public void setUp() throws Exception {
35 regexValidationPattern=new RegexValidationPattern();
36 }
37
38
39
40
41 @Test public final void testNumericPattern() {
42 regexValidationPattern.setPattern("[0-9]");
43
44 assertTrue(regexValidationPattern.matches("123456789"));
45 assertFalse(regexValidationPattern.matches("abc"));
46 }
47
48
49
50
51 @Test public final void testAlphaPattern() {
52 regexValidationPattern.setPattern("[a-zA-Z]");
53
54 assertTrue(regexValidationPattern.matches("abc"));
55 assertFalse(regexValidationPattern.matches("a12345"));
56 }
57
58
59
60
61 @Test public final void testAlphaNumericPattern() {
62 regexValidationPattern.setPattern("[a-zA-Z0-9]");
63
64 assertTrue(regexValidationPattern.matches("ab12345c"));
65 assertFalse(regexValidationPattern.matches("a1*234?"));
66 }
67
68 }