View Javadoc

1   /**
2    * Copyright 2005-2011 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.krad.datadictionary.validation.fieldlevel;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kns.datadictionary.validation.fieldlevel.EmailAddressValidationPattern;
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 EmailAddressValidationPatternTest extends KRADTestCase {
27      private EmailAddressValidationPattern pattern;
28  
29      @Override
30      public void setUp() throws Exception {
31          super.setUp();
32  
33          pattern = new EmailAddressValidationPattern();
34      }
35  
36  
37      @Test public final void testMatches_valid1() {
38          assertTrue(pattern.matches("ww5@a.b.c.org"));
39      }
40  
41      @Test public final void testMatches_valid2() {
42          assertTrue(pattern.matches("something.else@a2.com"));
43      }
44  
45      @Test public final void testMatches_valid3() {
46          assertTrue(pattern.matches("something_else@something.else.com"));
47      }
48  
49      @Test public final void testMatches_valid4() {
50          assertTrue(pattern.matches("something-else@et-tu.com"));
51      }
52  
53  
54      @Test public final void testMatches_invalid1() {
55          assertFalse(pattern.matches("a"));
56      }
57  
58      @Test public final void testMatches_invalid2() {
59          assertFalse(pattern.matches("@a.b.c.org"));
60      }
61  
62      @Test public final void testMatches_invalid3() {
63          assertFalse(pattern.matches("1@a.b.c.org"));
64      }
65  
66      @Test public final void testMatches_invalid4() {
67          assertFalse(pattern.matches("1@org"));
68      }
69  
70      @Test public final void testMatches_invalid5() {
71          assertFalse(pattern.matches("1@a"));
72      }
73  
74      @Test public final void testMatches_invalid6() {
75          assertFalse(pattern.matches(".@a.org"));
76      }
77  
78      @Test public final void testMatches_invalid7() {
79          assertFalse(pattern.matches("_@a.org"));
80      }
81  
82      @Test public final void testMatches_invalid8() {
83          assertFalse(pattern.matches("something@a.o-rg"));
84      }
85  }