Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0342ab5b authored by Paul Duffin's avatar Paul Duffin
Browse files

Move JUnit classes from here into external/junit

Checked that android.test.runner had the same classes in as
before the change.

These classes are legacy 3.8.1 classes, they are not in 4.10 at
all. They appear to have been left here by accident. Looking at
the history it appears that at one time there were copies of
JUnit 3.8.1 junit.runner classes in frameworks and
external/junit. The classes here were upgraded to 4.10 but even
though these classes had been deleted immediately after 3.8.2
was released they were not removed, instead they appear to have
been reformatted as part of the upgrade. The external/junit
source was upgraded to 4.10 about two weeks later which seems to
have been done correctly. About three months after that the
classes here that were duplicates of those in external/junit
were removed from here leaving the legacy classes from 3.8.1.

I could not find any usages of these classes and they are not in
the public API so they can probably be removed altogether.
However, for now I will simply move them into external/junit as
described and remove them when upgrading JUnit there to 4.12.

Bug: 30188076
Test: Built android.test.runner and checkapi
Change-Id: I88687889315c041d999fe7e61b9652ac8406165c
parent c6c005ef
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
http://www.opensource.org/licenses/cpl1.0.php
+0 −81
Original line number Diff line number Diff line
package junit.runner;

import java.util.*;
import java.io.*;

/**
 * An implementation of a TestCollector that consults the
 * class path. It considers all classes on the class path
 * excluding classes in JARs. It leaves it up to subclasses
 * to decide whether a class is a runnable Test.
 *
 * @see TestCollector
 * {@hide} - Not needed for 1.0 SDK
 */
public abstract class ClassPathTestCollector implements TestCollector {

    static final int SUFFIX_LENGTH= ".class".length();

    public ClassPathTestCollector() {
    }

    public Enumeration collectTests() {
        String classPath= System.getProperty("java.class.path");
        Hashtable result = collectFilesInPath(classPath);
        return result.elements();
    }

    public Hashtable collectFilesInPath(String classPath) {
        Hashtable result= collectFilesInRoots(splitClassPath(classPath));
        return result;
    }

    Hashtable collectFilesInRoots(Vector roots) {
        Hashtable result= new Hashtable(100);
        Enumeration e= roots.elements();
        while (e.hasMoreElements())
            gatherFiles(new File((String)e.nextElement()), "", result);
        return result;
    }

    void gatherFiles(File classRoot, String classFileName, Hashtable result) {
        File thisRoot= new File(classRoot, classFileName);
        if (thisRoot.isFile()) {
            if (isTestClass(classFileName)) {
                String className= classNameFromFile(classFileName);
                result.put(className, className);
            }
            return;
        }
        String[] contents= thisRoot.list();
        if (contents != null) {
            for (int i= 0; i < contents.length; i++)
                gatherFiles(classRoot, classFileName+File.separatorChar+contents[i], result);
        }
    }

    Vector splitClassPath(String classPath) {
        Vector result= new Vector();
        String separator= System.getProperty("path.separator");
        StringTokenizer tokenizer= new StringTokenizer(classPath, separator);
        while (tokenizer.hasMoreTokens())
            result.addElement(tokenizer.nextToken());
        return result;
    }

    protected boolean isTestClass(String classFileName) {
        return
                classFileName.endsWith(".class") &&
                classFileName.indexOf('$') < 0 &&
                classFileName.indexOf("Test") > 0;
    }

    protected String classNameFromFile(String classFileName) {
        // convert /a/b.class to a.b
        String s= classFileName.substring(0, classFileName.length()-SUFFIX_LENGTH);
        String s2= s.replace(File.separatorChar, '.');
        if (s2.startsWith("."))
            return s2.substring(1);
        return s2;
    }
}
+0 −28
Original line number Diff line number Diff line
package junit.runner;

// The following line was removed for compatibility with Android libraries.
//import java.awt.Component;

import junit.framework.*;

/**
 * A view to show a details about a failure
 * {@hide} - Not needed for 1.0 SDK
 */
public interface FailureDetailView {
    // The following definition was removed for compatibility with Android
    // libraries.
    //  /**
    //   * Returns the component used to present the TraceView
    //   */
    //  public Component getComponent();

    /**
     * Shows details of a TestFailure
     */
    public void showFailure(TestFailure failure);
    /**
     * Clears the view
     */
    public void clear();
}
+0 −69
Original line number Diff line number Diff line
package junit.runner;

import java.lang.reflect.*;
import junit.framework.*;

/**
 * An implementation of a TestCollector that loads
 * all classes on the class path and tests whether
 * it is assignable from Test or provides a static suite method.
 * @see TestCollector
 * {@hide} - Not needed for 1.0 SDK
 */
public class LoadingTestCollector extends ClassPathTestCollector {

    TestCaseClassLoader fLoader;

    public LoadingTestCollector() {
        fLoader= new TestCaseClassLoader();
    }

    protected boolean isTestClass(String classFileName) {
        try {
            if (classFileName.endsWith(".class")) {
                Class testClass= classFromFile(classFileName);
                return (testClass != null) && isTestClass(testClass);
            }
        }
        catch (ClassNotFoundException expected) {
        }
        catch (NoClassDefFoundError notFatal) {
        }
        return false;
    }

    Class classFromFile(String classFileName) throws ClassNotFoundException {
        String className= classNameFromFile(classFileName);
        if (!fLoader.isExcluded(className))
            return fLoader.loadClass(className, false);
        return null;
    }

    boolean isTestClass(Class testClass) {
        if (hasSuiteMethod(testClass))
            return true;
        if (Test.class.isAssignableFrom(testClass) &&
                Modifier.isPublic(testClass.getModifiers()) &&
                hasPublicConstructor(testClass))
            return true;
        return false;
    }

    boolean hasSuiteMethod(Class testClass) {
        try {
            testClass.getMethod(BaseTestRunner.SUITE_METHODNAME, new Class[0]);
        } catch(Exception e) {
            return false;
        }
        return true;
    }

    boolean hasPublicConstructor(Class testClass) {
        try {
            TestSuite.getTestConstructor(testClass);
        } catch(NoSuchMethodException e) {
            return false;
        }
        return true;
    }
}
+0 −20
Original line number Diff line number Diff line
package junit.runner;

/**
 * A TestSuite loader that can reload classes.
 * {@hide} - Not needed for 1.0 SDK
 */
public class ReloadingTestSuiteLoader implements TestSuiteLoader {

    public Class load(String suiteClassName) throws ClassNotFoundException {
        return createLoader().loadClass(suiteClassName, true);
    }

    public Class reload(Class aClass) throws ClassNotFoundException {
        return createLoader().loadClass(aClass.getName(), true);
    }

    protected TestCaseClassLoader createLoader() {
        return new TestCaseClassLoader();
    }
}
Loading