FileDocCategorySizeDatePackage
EclipseTestCollector.javaAPI DocAndroid 1.5 API3698Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.tests

EclipseTestCollector

public class EclipseTestCollector extends Object
Class for collecting all test cases in an eclipse plugin

Fields Summary
Constructors Summary
public EclipseTestCollector()
Constructor

        
    
Methods Summary
public voidaddTestCases(junit.framework.TestSuite suite, org.eclipse.core.runtime.Plugin plugin, java.lang.String expectedPackage)
Searches through given plugin, adding all TestCase classes to given suite

param
suite - TestSuite to add to
param
plugin - Plugin to search for tests
param
expectedPackage - expected package for tests. Only test classes that start with this package name will be added to suite

        if (plugin != null) {
            Enumeration<?> entries = plugin.getBundle().findEntries("/", "*.class", true);
    
            while (entries.hasMoreElements()) {
                URL entry = (URL)entries.nextElement();
                String filePath = entry.getPath().replace(".class", "");
                try {
                  Class<?> testClass = getClass(filePath, expectedPackage);
                  if (isTestClass(testClass)) {
                      suite.addTestSuite(testClass);
                  }
                } 
                catch (ClassNotFoundException e) {
                  // ignore, this is not the class we're looking for
                  //sLogger.log(Level.INFO, "Could not load class " + filePath);
              }
            }
        }
    
protected java.lang.ClassgetClass(java.lang.String filePath, java.lang.String expectedPackage)
Load the class given by the plugin aka bundle file path

param
filePath - path of class in bundle
param
expectedPackage - expected package of class
return
throws
ClassNotFoundException

        String dotPath = filePath.replace('/", '.");
        // remove the output folders, by finding where package name starts
        int index = dotPath.indexOf(expectedPackage);
        if (index == -1) {
            throw new ClassNotFoundException();
        }
        String packagePath = dotPath.substring(index);
        return Class.forName(packagePath);   
    
protected booleanhasPublicConstructor(java.lang.Class testClass)
Returns true if given class has a public constructor

param
testClass
return

        try {
            TestSuite.getTestConstructor(testClass);
        } catch(NoSuchMethodException e) {
            return false;
        }
        return true;
    
protected booleanisTestClass(java.lang.Class testClass)
Returns true if given class should be added to suite

param
testClass
return

        return TestCase.class.isAssignableFrom(testClass) &&
          Modifier.isPublic(testClass.getModifiers()) &&
          hasPublicConstructor(testClass);