NamesUtil { public static String createNewClassNameFromInterfaceName(String interfaceName) { int unqualifedNamePos = interfaceName.lastIndexOf('.')+1; String unqualifedInterfaceName = interfaceName.substring(unqualifedNamePos); unqualifedInterfaceName=unqualifedInterfaceName.replaceFirst("(^I(?=[A-Z])(nterface)?)|(I|i)nterface", ""); int genericQualifierPos = unqualifedInterfaceName.indexOf("<"); String result; if (genericQualifierPos<0) result=unqualifedInterfaceName+ImplClassSuffix; else { result=unqualifedInterfaceName.substring(0,genericQualifierPos)+ImplClassSuffix+unqualifedInterfaceName.substring(genericQualifierPos); } return result; } private  NamesUtil(); static boolean isJavaLangClassName(String identifier); static boolean isJavaUtilClassName(String identifier); static String makeSafeJavaIdentifier(String identifier); static String createNewClassNameFromInterfaceName(String interfaceName); static String getGenericQualifier(String className); static String[] getGenericQualifierNames(String className); static boolean hasGenericQualifier(String name); static String stripGenericQualifier(String className); static String stripArrrayQualifier(String className); static String ensureQualifedName(String name, String defaultPackage); static boolean isQualifiedName(String name); static String getUnqualifiedName(String name); static String getPackageFromQualifiedName(String name); static boolean hasPackage(String qualifiedName, String packageName); static boolean isGetterMethod(String methodName, String[] getterPrefixes); static boolean isSetterMethod(String methodName, String[] setterPrefixes); static String getWrapperTypeName(String typeName); static boolean hasWilcard(String wildcardSpecifier); static boolean matchingOverloads(String overloadNamesSpecifier1, String overloadNamesSpecifier2, boolean ignoreAllPackages); static final String ImplClassSuffix; }
@Test public void testNameFromInterface_InterfaceFilteretOut() { String actual = NamesUtil.createNewClassNameFromInterfaceName("TestInterface"); Assert.assertEquals("Class name not constructed correctly", "Test"+NamesUtil.ImplClassSuffix, actual); }
@Test public void testNameFromInterface_IFilteretOut() { String actual = NamesUtil.createNewClassNameFromInterfaceName("ITest"); Assert.assertEquals("Class name not constructed correctly", "Test"+NamesUtil.ImplClassSuffix, actual); }
@Test public void testNameFromInterface_INotFilteretOut() { String actual = NamesUtil.createNewClassNameFromInterfaceName("ImmutableBla"); Assert.assertEquals("Class name not constructed correctly", "ImmutableBla"+NamesUtil.ImplClassSuffix, actual); }
@Test public void testNameFromInterface_Simple() { String actual = NamesUtil.createNewClassNameFromInterfaceName("Test"); Assert.assertEquals("Class name not constructed correctly", "Test"+NamesUtil.ImplClassSuffix, actual); }