Merge "Cleanup a.t.TestGrouping"
am: 01dcf54e9a
Change-Id: I58a278b7c45afe27309cf0029e9fb8fd452b22f2
This commit is contained in:
@@ -44,23 +44,23 @@ import java.util.TreeSet;
|
|||||||
*
|
*
|
||||||
* {@hide} Not needed for 1.0 SDK.
|
* {@hide} Not needed for 1.0 SDK.
|
||||||
*/
|
*/
|
||||||
public class TestGrouping {
|
class TestGrouping {
|
||||||
|
|
||||||
private static final String LOG_TAG = "TestGrouping";
|
private static final String LOG_TAG = "TestGrouping";
|
||||||
|
|
||||||
SortedSet<Class<? extends TestCase>> testCaseClasses;
|
private final SortedSet<Class<? extends TestCase>> testCaseClasses;
|
||||||
|
|
||||||
public static final Comparator<Class<? extends TestCase>> SORT_BY_SIMPLE_NAME
|
static final Comparator<Class<? extends TestCase>> SORT_BY_SIMPLE_NAME
|
||||||
= new SortBySimpleName();
|
= new SortBySimpleName();
|
||||||
|
|
||||||
public static final Comparator<Class<? extends TestCase>> SORT_BY_FULLY_QUALIFIED_NAME
|
static final Comparator<Class<? extends TestCase>> SORT_BY_FULLY_QUALIFIED_NAME
|
||||||
= new SortByFullyQualifiedName();
|
= new SortByFullyQualifiedName();
|
||||||
|
|
||||||
protected String firstIncludedPackage = null;
|
private final ClassLoader classLoader;
|
||||||
private ClassLoader classLoader;
|
|
||||||
|
|
||||||
public TestGrouping(Comparator<Class<? extends TestCase>> comparator) {
|
TestGrouping(Comparator<Class<? extends TestCase>> comparator, ClassLoader classLoader) {
|
||||||
testCaseClasses = new TreeSet<Class<? extends TestCase>>(comparator);
|
testCaseClasses = new TreeSet<Class<? extends TestCase>>(comparator);
|
||||||
|
this.classLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,15 +77,11 @@ public class TestGrouping {
|
|||||||
return testMethods;
|
return testMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Method> getTestMethods(Class<? extends TestCase> testCaseClass) {
|
private List<Method> getTestMethods(Class<? extends TestCase> testCaseClass) {
|
||||||
List<Method> methods = Arrays.asList(testCaseClass.getMethods());
|
List<Method> methods = Arrays.asList(testCaseClass.getMethods());
|
||||||
return select(methods, new TestMethodPredicate());
|
return select(methods, new TestMethodPredicate());
|
||||||
}
|
}
|
||||||
|
|
||||||
SortedSet<Class<? extends TestCase>> getTestCaseClasses() {
|
|
||||||
return testCaseClasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
@@ -110,9 +106,8 @@ public class TestGrouping {
|
|||||||
* or in a sub-package.
|
* or in a sub-package.
|
||||||
*
|
*
|
||||||
* @param packageNames Names of packages to add.
|
* @param packageNames Names of packages to add.
|
||||||
* @return The {@link TestGrouping} for method chaining.
|
|
||||||
*/
|
*/
|
||||||
public TestGrouping addPackagesRecursive(String... packageNames) {
|
void addPackagesRecursive(String... packageNames) {
|
||||||
for (String packageName : packageNames) {
|
for (String packageName : packageNames) {
|
||||||
List<Class<? extends TestCase>> addedClasses = testCaseClassesInPackage(packageName);
|
List<Class<? extends TestCase>> addedClasses = testCaseClassesInPackage(packageName);
|
||||||
if (addedClasses.isEmpty()) {
|
if (addedClasses.isEmpty()) {
|
||||||
@@ -120,33 +115,19 @@ public class TestGrouping {
|
|||||||
+ "' could not be found or has no tests");
|
+ "' could not be found or has no tests");
|
||||||
}
|
}
|
||||||
testCaseClasses.addAll(addedClasses);
|
testCaseClasses.addAll(addedClasses);
|
||||||
if (firstIncludedPackage == null) {
|
|
||||||
firstIncludedPackage = packageName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exclude all tests in the given packages and all their sub-packages, unless otherwise
|
* Exclude all tests in the given packages and all their sub-packages, unless otherwise
|
||||||
* specified.
|
* specified.
|
||||||
*
|
*
|
||||||
* @param packageNames Names of packages to remove.
|
* @param packageNames Names of packages to remove.
|
||||||
* @return The {@link TestGrouping} for method chaining.
|
|
||||||
*/
|
*/
|
||||||
public TestGrouping removePackagesRecursive(String... packageNames) {
|
void removePackagesRecursive(String... packageNames) {
|
||||||
for (String packageName : packageNames) {
|
for (String packageName : packageNames) {
|
||||||
testCaseClasses.removeAll(testCaseClassesInPackage(packageName));
|
testCaseClasses.removeAll(testCaseClassesInPackage(packageName));
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The first package name passed to {@link #addPackagesRecursive(String[])}, or null
|
|
||||||
* if that method was never called.
|
|
||||||
*/
|
|
||||||
public String getFirstIncludedPackage() {
|
|
||||||
return firstIncludedPackage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Class<? extends TestCase>> testCaseClassesInPackage(String packageName) {
|
private List<Class<? extends TestCase>> testCaseClassesInPackage(String packageName) {
|
||||||
@@ -176,10 +157,6 @@ public class TestGrouping {
|
|||||||
return selectedItems;
|
return selectedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClassLoader(ClassLoader classLoader) {
|
|
||||||
this.classLoader = classLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort classes by their simple names (i.e. without the package prefix), using
|
* Sort classes by their simple names (i.e. without the package prefix), using
|
||||||
* their packages to sort classes with the same name.
|
* their packages to sort classes with the same name.
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ import java.util.Collections;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public class TestSuiteBuilder {
|
public class TestSuiteBuilder {
|
||||||
|
|
||||||
private Context context;
|
private final TestGrouping testGrouping;
|
||||||
private final TestGrouping testGrouping = new TestGrouping(SORT_BY_FULLY_QUALIFIED_NAME);
|
|
||||||
private final Set<Predicate<TestMethod>> predicates = new HashSet<Predicate<TestMethod>>();
|
private final Set<Predicate<TestMethod>> predicates = new HashSet<Predicate<TestMethod>>();
|
||||||
private List<TestCase> testCases;
|
private List<TestCase> testCases;
|
||||||
private TestSuite rootSuite;
|
private TestSuite rootSuite;
|
||||||
@@ -67,7 +66,7 @@ public class TestSuiteBuilder {
|
|||||||
|
|
||||||
public TestSuiteBuilder(String name, ClassLoader classLoader) {
|
public TestSuiteBuilder(String name, ClassLoader classLoader) {
|
||||||
this.suiteName = name;
|
this.suiteName = name;
|
||||||
this.testGrouping.setClassLoader(classLoader);
|
this.testGrouping = new TestGrouping(SORT_BY_FULLY_QUALIFIED_NAME, classLoader);
|
||||||
this.testCases = new ArrayList<>();
|
this.testCases = new ArrayList<>();
|
||||||
addRequirements(REJECT_SUPPRESSED);
|
addRequirements(REJECT_SUPPRESSED);
|
||||||
}
|
}
|
||||||
@@ -244,15 +243,6 @@ public class TestSuiteBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the test package that represents the packages that were included for our test suite.
|
|
||||||
*
|
|
||||||
* {@hide} Not needed for 1.0 SDK.
|
|
||||||
*/
|
|
||||||
protected TestGrouping getTestGrouping() {
|
|
||||||
return testGrouping;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean satisfiesAllPredicates(TestMethod test) {
|
private boolean satisfiesAllPredicates(TestMethod test) {
|
||||||
for (Predicate<TestMethod> predicate : predicates) {
|
for (Predicate<TestMethod> predicate : predicates) {
|
||||||
if (!predicate.apply(test)) {
|
if (!predicate.apply(test)) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class TestGroupingTest extends TestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mGrouping = new TestGrouping(TestGrouping.SORT_BY_SIMPLE_NAME);
|
mGrouping = new TestGrouping(TestGrouping.SORT_BY_SIMPLE_NAME, getClass().getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user