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.ZipcodeValidationPattern; 020 import org.kuali.test.KRADTestCase; 021 022 import static org.junit.Assert.assertFalse; 023 import static org.junit.Assert.assertTrue; 024 025 /** 026 * ZipcodeValidationPatternTest tests {@link ZipcodeValidationPattern} 027 * 028 * <p>Valid zip code values should match</p> 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032 public class ZipcodeValidationPatternTest extends KRADTestCase { 033 private ZipcodeValidationPattern pattern; 034 035 @Override 036 public void setUp() throws Exception { 037 super.setUp(); 038 039 pattern = new ZipcodeValidationPattern(); 040 } 041 042 043 @Test public final void testMatches_5digit_valid() { 044 assertTrue(pattern.matches("12345")); 045 } 046 047 @Test public final void testMatches_9digit_valid() { 048 assertTrue(pattern.matches("12345-1234")); 049 } 050 051 @Test public final void testMatches_invalid1() { 052 assertFalse(pattern.matches("123456")); 053 } 054 055 @Test public final void testMatches_invalid2() { 056 assertFalse(pattern.matches("1234")); 057 } 058 059 @Test public final void testMatches_invalid3() { 060 assertFalse(pattern.matches("12345-12345")); 061 } 062 063 @Test public final void testMatches_invalid4() { 064 assertFalse(pattern.matches("12345-123")); 065 } 066 }