001    /*
002     * Copyright 2006-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.kns.datadictionary.validation.fieldlevel;
017    
018    import org.junit.Test;
019    import org.kuali.test.KNSTestCase;
020    
021    import static org.junit.Assert.assertFalse;
022    import static org.junit.Assert.assertTrue;
023    
024    
025    public class EmailAddressValidationPatternTest extends KNSTestCase {
026        private EmailAddressValidationPattern pattern;
027    
028        @Override
029        public void setUp() throws Exception {
030            super.setUp();
031    
032            pattern = new EmailAddressValidationPattern();
033        }
034    
035    
036        @Test public final void testMatches_valid1() {
037            assertTrue(pattern.matches("ww5@a.b.c.org"));
038        }
039    
040        @Test public final void testMatches_valid2() {
041            assertTrue(pattern.matches("something.else@a2.com"));
042        }
043    
044        @Test public final void testMatches_valid3() {
045            assertTrue(pattern.matches("something_else@something.else.com"));
046        }
047    
048        @Test public final void testMatches_valid4() {
049            assertTrue(pattern.matches("something-else@et-tu.com"));
050        }
051    
052    
053        @Test public final void testMatches_invalid1() {
054            assertFalse(pattern.matches("a"));
055        }
056    
057        @Test public final void testMatches_invalid2() {
058            assertFalse(pattern.matches("@a.b.c.org"));
059        }
060    
061        @Test public final void testMatches_invalid3() {
062            assertFalse(pattern.matches("1@a.b.c.org"));
063        }
064    
065        @Test public final void testMatches_invalid4() {
066            assertFalse(pattern.matches("1@org"));
067        }
068    
069        @Test public final void testMatches_invalid5() {
070            assertFalse(pattern.matches("1@a"));
071        }
072    
073        @Test public final void testMatches_invalid6() {
074            assertFalse(pattern.matches(".@a.org"));
075        }
076    
077        @Test public final void testMatches_invalid7() {
078            assertFalse(pattern.matches("_@a.org"));
079        }
080    
081        @Test public final void testMatches_invalid8() {
082            assertFalse(pattern.matches("something@a.o-rg"));
083        }
084    }