001    /**
002     * Copyright 2005-2013 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.JavaClassValidationPattern;
020    import org.kuali.rice.krad.test.KRADTestCase;
021    
022    import static org.junit.Assert.assertFalse;
023    import static org.junit.Assert.assertTrue;
024    
025    /**
026     * JavaClassValidationPatternTest tests {@link JavaClassValidationPattern}
027     *
028     * <p>Valid Java class file names should match</p>
029     *
030     * @author Kuali Rice Team (rice.collab@kuali.org)
031     */
032    public class JavaClassValidationPatternTest extends KRADTestCase {
033        JavaClassValidationPattern pattern;
034    
035        @Override
036        public void setUp() throws Exception {
037            super.setUp();
038    
039            pattern = new JavaClassValidationPattern();
040        }
041    
042        @Test public final void testMatches_actualClass() {
043            assertTrue(pattern.matches(String.class.getName()));
044        }
045    
046        @Test public final void testMatches_fictitiousClass() {
047            assertTrue(pattern.matches("something.wicked.this.way.Comes"));
048        }
049    
050        @Test public final void testMatches_unqualifiedClass() {
051            assertTrue(pattern.matches("String"));
052        }
053    
054        @Test public final void testMatches_invalidClassname1() {
055            assertFalse(pattern.matches("23Tests"));
056        }
057    
058        @Test public final void testMatches_invalidClassname2() {
059            assertFalse(pattern.matches("more tests"));
060        }
061    
062        @Test public final void testMatches_invalidClassname3() {
063            assertFalse(pattern.matches("more.and.more:tests"));
064        }
065    
066        @Test public final void testMatches_invalidClassname4() {
067            assertFalse(pattern.matches("still.more.tests."));
068        }
069    }