/** * Get the class name without the qualified package name. * * @param className the className to get the short name for * @return the class name of the class without the package name * @throws IllegalArgumentException if the className is empty */ public static String getShortName(String className) { Assert.hasLength(className, "Class name must not be empty"); int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR); int nameEndIndex = className.indexOf(CGLIB_CLASS_SEPARATOR); if (nameEndIndex == -1) { nameEndIndex = className.length(); } String shortName = className.substring(lastDotIndex + 1, nameEndIndex); shortName = shortName.replace(INNER_CLASS_SEPARATOR, PACKAGE_SEPARATOR); return shortName; }
@Test(expected = IllegalArgumentException.class) public void hasLengthWithEmptyStringThrowsException() throws Exception { Assert.hasLength(""); }
@Test public void hasLengthSunnyDay() throws Exception { Assert.hasLength("I Heart ..."); }
@Test(expected = IllegalArgumentException.class) public void testHasLengthWithNullStringThrowsException() throws Exception { Assert.hasLength(null); }
@Test public void hasLengthWithWhitespaceOnlyStringDoesNotThrowException() throws Exception { Assert.hasLength("\t "); }