001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.datadictionary.validation.fieldlevel;
017
018 import org.junit.Test;
019 import org.kuali.rice.kns.datadictionary.validation.fieldlevel.EmailAddressValidationPattern;
020 import org.kuali.test.KRADTestCase;
021
022 import static org.junit.Assert.assertFalse;
023 import static org.junit.Assert.assertTrue;
024
025
026 public class EmailAddressValidationPatternTest extends KRADTestCase {
027 private EmailAddressValidationPattern pattern;
028
029 @Override
030 public void setUp() throws Exception {
031 super.setUp();
032
033 pattern = new EmailAddressValidationPattern();
034 }
035
036
037 @Test public final void testMatches_valid1() {
038 assertTrue(pattern.matches("ww5@a.b.c.org"));
039 }
040
041 @Test public final void testMatches_valid2() {
042 assertTrue(pattern.matches("something.else@a2.com"));
043 }
044
045 @Test public final void testMatches_valid3() {
046 assertTrue(pattern.matches("something_else@something.else.com"));
047 }
048
049 @Test public final void testMatches_valid4() {
050 assertTrue(pattern.matches("something-else@et-tu.com"));
051 }
052
053
054 @Test public final void testMatches_invalid1() {
055 assertFalse(pattern.matches("a"));
056 }
057
058 @Test public final void testMatches_invalid2() {
059 assertFalse(pattern.matches("@a.b.c.org"));
060 }
061
062 @Test public final void testMatches_invalid3() {
063 assertFalse(pattern.matches("1@a.b.c.org"));
064 }
065
066 @Test public final void testMatches_invalid4() {
067 assertFalse(pattern.matches("1@org"));
068 }
069
070 @Test public final void testMatches_invalid5() {
071 assertFalse(pattern.matches("1@a"));
072 }
073
074 @Test public final void testMatches_invalid6() {
075 assertFalse(pattern.matches(".@a.org"));
076 }
077
078 @Test public final void testMatches_invalid7() {
079 assertFalse(pattern.matches("_@a.org"));
080 }
081
082 @Test public final void testMatches_invalid8() {
083 assertFalse(pattern.matches("something@a.o-rg"));
084 }
085 }