001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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 */ 016package org.modeshape.common.util; 017 018import org.junit.Test; 019import static org.hamcrest.core.Is.is; 020import static org.junit.Assert.assertThat; 021 022/** 023 * @author Randall Hauch 024 */ 025public class ClassUtilTest { 026 027 @Test 028 public void shouldConsiderValidClassnamesToBeValid() { 029 assertValidClassname(this.getClass().getName()); 030 assertValidClassname("org.jboss.a.b.c.d.e.f.SomeClass"); 031 assertValidClassname("SomeClass"); 032 } 033 034 @Test 035 public void shouldConsiderInvalidClassnamesToBeInvalid() { 036 assertNotValidClassname(null); 037 assertNotValidClassname(""); 038 assertNotValidClassname(" " + this.getClass().getName() + " \t "); 039 assertNotValidClassname("1.2.3.4"); 040 assertNotValidClassname("org.jboss.a.b.c.d.e.f.2SomeClass"); 041 assertNotValidClassname("org/jboss/a/b/c/d/e.f.SomeClass"); 042 } 043 044 protected void assertValidClassname( String classname ) { 045 assertThat(ClassUtil.isFullyQualifiedClassname(classname), is(true)); 046 } 047 048 protected void assertNotValidClassname( String classname ) { 049 assertThat(ClassUtil.isFullyQualifiedClassname(classname), is(false)); 050 } 051 052}