Merge "Cleanup a.t.TestGrouping"

This commit is contained in:
Treehugger Robot
2017-06-21 09:03:26 +00:00
committed by Gerrit Code Review
3 changed files with 13 additions and 46 deletions

View File

@@ -44,23 +44,23 @@ import java.util.TreeSet;
*
* {@hide} Not needed for 1.0 SDK.
*/
public class TestGrouping {
class 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();
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();
protected String firstIncludedPackage = null;
private ClassLoader classLoader;
private final ClassLoader classLoader;
public TestGrouping(Comparator<Class<? extends TestCase>> comparator) {
TestGrouping(Comparator<Class<? extends TestCase>> comparator, ClassLoader classLoader) {
testCaseClasses = new TreeSet<Class<? extends TestCase>>(comparator);
this.classLoader = classLoader;
}
/**
@@ -77,15 +77,11 @@ public class TestGrouping {
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());
return select(methods, new TestMethodPredicate());
}
SortedSet<Class<? extends TestCase>> getTestCaseClasses() {
return testCaseClasses;
}
public boolean equals(Object o) {
if (this == o) {
return true;
@@ -110,9 +106,8 @@ public class TestGrouping {
* or in a sub-package.
*
* @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) {
List<Class<? extends TestCase>> addedClasses = testCaseClassesInPackage(packageName);
if (addedClasses.isEmpty()) {
@@ -120,11 +115,7 @@ public class TestGrouping {
+ "' could not be found or has no tests");
}
testCaseClasses.addAll(addedClasses);
if (firstIncludedPackage == null) {
firstIncludedPackage = packageName;
}
}
return this;
}
/**
@@ -132,21 +123,11 @@ public class TestGrouping {
* specified.
*
* @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) {
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) {
@@ -176,10 +157,6 @@ public class TestGrouping {
return selectedItems;
}
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
/**
* Sort classes by their simple names (i.e. without the package prefix), using
* their packages to sort classes with the same name.

View File

@@ -44,8 +44,7 @@ import java.util.Collections;
@Deprecated
public class TestSuiteBuilder {
private Context context;
private final TestGrouping testGrouping = new TestGrouping(SORT_BY_FULLY_QUALIFIED_NAME);
private final TestGrouping testGrouping;
private final Set<Predicate<TestMethod>> predicates = new HashSet<Predicate<TestMethod>>();
private List<TestCase> testCases;
private TestSuite rootSuite;
@@ -67,7 +66,7 @@ public class TestSuiteBuilder {
public TestSuiteBuilder(String name, ClassLoader classLoader) {
this.suiteName = name;
this.testGrouping.setClassLoader(classLoader);
this.testGrouping = new TestGrouping(SORT_BY_FULLY_QUALIFIED_NAME, classLoader);
this.testCases = new ArrayList<>();
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) {
for (Predicate<TestMethod> predicate : predicates) {
if (!predicate.apply(test)) {

View File

@@ -30,7 +30,7 @@ public class TestGroupingTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
mGrouping = new TestGrouping(TestGrouping.SORT_BY_SIMPLE_NAME);
mGrouping = new TestGrouping(TestGrouping.SORT_BY_SIMPLE_NAME, getClass().getClassLoader());
}
/**