FileDocCategorySizeDatePackage
TestMethod.javaAPI DocAndroid 1.5 API4902Wed May 06 22:42:02 BST 2009android.test.suitebuilder

TestMethod

public class TestMethod extends Object
Represents a test to be run. Can be constructed without instantiating the TestCase or even loading the class.

Fields Summary
private final String
enclosingClassname
private final String
testMethodName
private final Class
enclosingClass
Constructors Summary
public TestMethod(Method method, Class enclosingClass)

        this(method.getName(), enclosingClass);
    
public TestMethod(String methodName, Class enclosingClass)

        this.enclosingClass = enclosingClass;
        this.enclosingClassname = enclosingClass.getName();
        this.testMethodName = methodName;
    
public TestMethod(junit.framework.TestCase testCase)

        this(testCase.getName(), testCase.getClass());
    
Methods Summary
public junit.framework.TestCasecreateTest()

        return instantiateTest(enclosingClass, testMethodName);
    
public booleanequals(java.lang.Object o)

        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        TestMethod that = (TestMethod) o;

        if (enclosingClassname != null
                ? !enclosingClassname.equals(that.enclosingClassname)
                : that.enclosingClassname != null) {
            return false;
        }
        if (testMethodName != null
                ? !testMethodName.equals(that.testMethodName)
                : that.testMethodName != null) {
            return false;
        }
        return true;
    
public TgetAnnotation(java.lang.Class annotationClass)

        try {
            return getEnclosingClass().getMethod(getName()).getAnnotation(annotationClass);
        } catch (NoSuchMethodException e) {
            return null;
        }
    
public java.lang.ClassgetEnclosingClass()

        return enclosingClass;
    
public java.lang.StringgetEnclosingClassname()

        return enclosingClassname;
    
public java.lang.StringgetName()

        return testMethodName;
    
public inthashCode()

        int result;
        result = (enclosingClassname != null ? enclosingClassname.hashCode() : 0);
        result = 31 * result + (testMethodName != null ? testMethodName.hashCode() : 0);
        return result;
    
private junit.framework.TestCaseinstantiateTest(java.lang.Class testCaseClass, java.lang.String testName)

        Constructor[] constructors = testCaseClass.getConstructors();

        if (constructors.length == 0) {
            return instantiateTest(testCaseClass.getSuperclass(), testName);
        } else {
            for (Constructor constructor : constructors) {
                Class[] params = constructor.getParameterTypes();
                if (noargsConstructor(params)) {
                    TestCase test = ((Constructor<? extends TestCase>) constructor).newInstance();
                    // JUnit will run just the one test if you call
                    // {@link TestCase#setName(String)}
                    test.setName(testName);
                    return test;
                } else if (singleStringConstructor(params)) {
                    return ((Constructor<? extends TestCase>) constructor)
                            .newInstance(testName);
                }
            }
        }
        throw new RuntimeException("Unable to locate a constructor for "
                + testCaseClass.getName());
    
private booleannoargsConstructor(java.lang.Class[] params)

        return params.length == 0;
    
private booleansingleStringConstructor(java.lang.Class[] params)

        return (params.length == 1) && (params[0].equals(String.class));
    
public java.lang.StringtoString()

        return enclosingClassname + "." + testMethodName;