FileDocCategorySizeDatePackage
RenameClassAdapterTest.javaAPI DocAndroid 5.1 API4237Thu Mar 12 22:22:44 GMT 2015com.android.tools.layoutlib.create

RenameClassAdapterTest

public class RenameClassAdapterTest extends Object

Fields Summary
private RenameClassAdapter
mOuter
private RenameClassAdapter
mInner
Constructors Summary
Methods Summary
public voidsetUp()

        mOuter = new RenameClassAdapter(null, // cv
                                         "com.pack.Old",
                                         "org.blah.New");

        mInner = new RenameClassAdapter(null, // cv
                                         "com.pack.Old$Inner",
                                         "org.blah.New$Inner");
    
public voidtearDown()

    
public voidtestRenameInternalType()
Renames an internal type name, e.g. "com.package.MyClass". If the type doesn't need to be renamed, returns the input string as-is.

        // an actual FQCN
        assertEquals("org.blah.New", mOuter.renameInternalType("com.pack.Old"));
        assertEquals("org.blah.New$Inner", mOuter.renameInternalType("com.pack.Old$Inner"));

        assertEquals("org.blah.New$Other", mInner.renameInternalType("com.pack.Old$Other"));
        assertEquals("org.blah.New$Other", mInner.renameInternalType("com.pack.Old$Other"));
    
public voidtestRenameMethodDesc()
Renames a method descriptor, i.e. applies renameType to all arguments and to the return value.

        assertEquals("(IDLorg.blah.New;[Lorg.blah.New$Inner;)Lorg.blah.New$Other;",
               mOuter.renameMethodDesc("(IDLcom.pack.Old;[Lcom.pack.Old$Inner;)Lcom.pack.Old$Other;"));
    
public voidtestRenameType()
Renames an object type, e.g. "Lcom.package.MyClass;" or an array type that has an object element, e.g. "[Lcom.package.MyClass;" If the type doesn't need to be renamed, returns the internal name of the input type.

        // Skip. This is actually tested by testRenameTypeDesc above.
    
public voidtestRenameTypeDesc()
Renames a type, e.g. "Lcom.package.My;" If the type doesn't need to be renamed, returns the input string as-is.


        // primitive types are left untouched
        assertEquals("I", mOuter.renameTypeDesc("I"));
        assertEquals("D", mOuter.renameTypeDesc("D"));
        assertEquals("V", mOuter.renameTypeDesc("V"));

        // object types that need no renaming are left untouched
        assertEquals("Lcom.package.MyClass;", mOuter.renameTypeDesc("Lcom.package.MyClass;"));
        assertEquals("Lcom.package.MyClass;", mInner.renameTypeDesc("Lcom.package.MyClass;"));

        // object types that match the requirements
        assertEquals("Lorg.blah.New;", mOuter.renameTypeDesc("Lcom.pack.Old;"));
        assertEquals("Lorg.blah.New$Inner;", mInner.renameTypeDesc("Lcom.pack.Old$Inner;"));
        // inner classes match the base type which is being renamed
        assertEquals("Lorg.blah.New$Other;", mOuter.renameTypeDesc("Lcom.pack.Old$Other;"));
        assertEquals("Lorg.blah.New$Other;", mInner.renameTypeDesc("Lcom.pack.Old$Other;"));

        // arrays
        assertEquals("[Lorg.blah.New;",  mOuter.renameTypeDesc("[Lcom.pack.Old;"));
        assertEquals("[[Lorg.blah.New;", mOuter.renameTypeDesc("[[Lcom.pack.Old;"));

        assertEquals("[Lorg.blah.New;",  mInner.renameTypeDesc("[Lcom.pack.Old;"));
        assertEquals("[[Lorg.blah.New;", mInner.renameTypeDesc("[[Lcom.pack.Old;"));