Merge changes I4c0e7fdd,I9ea3827a
* changes: Remove dependency on internal FileUtils class Remove dependency on com.google.android.collect classes
This commit is contained in:
@@ -20,8 +20,7 @@ import android.app.Instrumentation;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.PerformanceCollector.PerformanceResultsWriter;
|
import android.os.PerformanceCollector.PerformanceResultsWriter;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestListener;
|
import junit.framework.TestListener;
|
||||||
@@ -48,7 +47,7 @@ public class AndroidTestRunner extends BaseTestRunner {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private boolean mSkipExecution = false;
|
private boolean mSkipExecution = false;
|
||||||
|
|
||||||
private List<TestListener> mTestListeners = Lists.newArrayList();
|
private List<TestListener> mTestListeners = new ArrayList<>();
|
||||||
private Instrumentation mInstrumentation;
|
private Instrumentation mInstrumentation;
|
||||||
private PerformanceResultsWriter mPerfWriter;
|
private PerformanceResultsWriter mPerfWriter;
|
||||||
|
|
||||||
@@ -58,7 +57,8 @@ public class AndroidTestRunner extends BaseTestRunner {
|
|||||||
|
|
||||||
if (shouldRunSingleTestMethod(testMethodName, testClass)) {
|
if (shouldRunSingleTestMethod(testMethodName, testClass)) {
|
||||||
TestCase testCase = buildSingleTestMethod(testClass, testMethodName);
|
TestCase testCase = buildSingleTestMethod(testClass, testMethodName);
|
||||||
mTestCases = Lists.newArrayList(testCase);
|
mTestCases = new ArrayList<>();
|
||||||
|
mTestCases.add(testCase);
|
||||||
mTestClassName = testClass.getSimpleName();
|
mTestClassName = testClass.getSimpleName();
|
||||||
} else {
|
} else {
|
||||||
setTest(getTest(testClass), testClass);
|
setTest(getTest(testClass), testClass);
|
||||||
|
|||||||
@@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package android.test;
|
package android.test;
|
||||||
|
|
||||||
import com.google.android.collect.Sets;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +43,7 @@ public class ClassPathPackageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<ClassPathPackageInfo> getSubpackages() {
|
public Set<ClassPathPackageInfo> getSubpackages() {
|
||||||
Set<ClassPathPackageInfo> info = Sets.newHashSet();
|
Set<ClassPathPackageInfo> info = new HashSet<>();
|
||||||
for (String name : subpackageNames) {
|
for (String name : subpackageNames) {
|
||||||
info.add(source.getPackageInfo(name));
|
info.add(source.getPackageInfo(name));
|
||||||
}
|
}
|
||||||
@@ -52,7 +51,7 @@ public class ClassPathPackageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<Class<?>> getTopLevelClassesRecursive() {
|
public Set<Class<?>> getTopLevelClassesRecursive() {
|
||||||
Set<Class<?>> set = Sets.newHashSet();
|
Set<Class<?>> set = new HashSet<>();
|
||||||
addTopLevelClassesTo(set);
|
addTopLevelClassesTo(set);
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,13 @@
|
|||||||
package android.test;
|
package android.test;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.google.android.collect.Maps;
|
|
||||||
import com.google.android.collect.Sets;
|
|
||||||
import dalvik.system.DexFile;
|
import dalvik.system.DexFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
@@ -57,7 +57,7 @@ public class ClassPathPackageInfoSource {
|
|||||||
private static String[] apkPaths;
|
private static String[] apkPaths;
|
||||||
|
|
||||||
// A cache of jar file contents
|
// A cache of jar file contents
|
||||||
private final Map<File, Set<String>> jarFiles = Maps.newHashMap();
|
private final Map<File, Set<String>> jarFiles = new HashMap<>();
|
||||||
private ClassLoader classLoader;
|
private ClassLoader classLoader;
|
||||||
|
|
||||||
ClassPathPackageInfoSource() {
|
ClassPathPackageInfoSource() {
|
||||||
@@ -76,7 +76,7 @@ public class ClassPathPackageInfoSource {
|
|||||||
private ClassPathPackageInfo createPackageInfo(String packageName) {
|
private ClassPathPackageInfo createPackageInfo(String packageName) {
|
||||||
Set<String> subpackageNames = new TreeSet<String>();
|
Set<String> subpackageNames = new TreeSet<String>();
|
||||||
Set<String> classNames = new TreeSet<String>();
|
Set<String> classNames = new TreeSet<String>();
|
||||||
Set<Class<?>> topLevelClasses = Sets.newHashSet();
|
Set<Class<?>> topLevelClasses = new HashSet<>();
|
||||||
findClasses(packageName, classNames, subpackageNames);
|
findClasses(packageName, classNames, subpackageNames);
|
||||||
for (String className : classNames) {
|
for (String className : classNames) {
|
||||||
if (className.endsWith(".R") || className.endsWith(".Manifest")) {
|
if (className.endsWith(".R") || className.endsWith(".Manifest")) {
|
||||||
@@ -248,7 +248,7 @@ public class ClassPathPackageInfoSource {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
Set<String> entryNames = jarFiles.get(jarFile);
|
Set<String> entryNames = jarFiles.get(jarFile);
|
||||||
if (entryNames == null) {
|
if (entryNames == null) {
|
||||||
entryNames = Sets.newHashSet();
|
entryNames = new HashSet<>();
|
||||||
ZipFile zipFile = new ZipFile(jarFile);
|
ZipFile zipFile = new ZipFile(jarFile);
|
||||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
|
|||||||
@@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
package android.test;
|
package android.test;
|
||||||
|
|
||||||
import com.google.android.collect.Sets;
|
|
||||||
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +41,7 @@ public class DatabaseTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> getSchemaSet(SQLiteDatabase db) {
|
private static Set<String> getSchemaSet(SQLiteDatabase db) {
|
||||||
Set<String> schemaSet = Sets.newHashSet();
|
Set<String> schemaSet = new HashSet<>();
|
||||||
|
|
||||||
Cursor entityCursor = db.rawQuery("SELECT sql FROM sqlite_master", null);
|
Cursor entityCursor = db.rawQuery("SELECT sql FROM sqlite_master", null);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package android.test;
|
package android.test;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
|
||||||
|
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.AccountManagerCallback;
|
import android.accounts.AccountManagerCallback;
|
||||||
import android.accounts.AccountManagerFuture;
|
import android.accounts.AccountManagerFuture;
|
||||||
@@ -38,6 +36,7 @@ import android.os.Handler;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ public class IsolatedContext extends ContextWrapper {
|
|||||||
private ContentResolver mResolver;
|
private ContentResolver mResolver;
|
||||||
private final MockAccountManager mMockAccountManager;
|
private final MockAccountManager mMockAccountManager;
|
||||||
|
|
||||||
private List<Intent> mBroadcastIntents = Lists.newArrayList();
|
private List<Intent> mBroadcastIntents = new ArrayList<>();
|
||||||
|
|
||||||
public IsolatedContext(
|
public IsolatedContext(
|
||||||
ContentResolver resolver, Context targetContext) {
|
ContentResolver resolver, Context targetContext) {
|
||||||
@@ -67,7 +66,7 @@ public class IsolatedContext extends ContextWrapper {
|
|||||||
/** Returns the list of intents that were broadcast since the last call to this method. */
|
/** Returns the list of intents that were broadcast since the last call to this method. */
|
||||||
public List<Intent> getAndClearBroadcastIntents() {
|
public List<Intent> getAndClearBroadcastIntents() {
|
||||||
List<Intent> intents = mBroadcastIntents;
|
List<Intent> intents = mBroadcastIntents;
|
||||||
mBroadcastIntents = Lists.newArrayList();
|
mBroadcastIntents = new ArrayList<>();
|
||||||
return intents;
|
return intents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,24 @@
|
|||||||
|
|
||||||
package android.test;
|
package android.test;
|
||||||
|
|
||||||
import com.google.android.collect.Sets;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.database.DatabaseErrorHandler;
|
import android.database.DatabaseErrorHandler;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.FileUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.attribute.PosixFilePermission;
|
||||||
|
import java.nio.file.attribute.PosixFilePermissions;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +52,8 @@ public class RenamingDelegatingContext extends ContextWrapper {
|
|||||||
private File mCacheDir;
|
private File mCacheDir;
|
||||||
private final Object mSync = new Object();
|
private final Object mSync = new Object();
|
||||||
|
|
||||||
private Set<String> mDatabaseNames = Sets.newHashSet();
|
private Set<String> mDatabaseNames = new HashSet<>();
|
||||||
private Set<String> mFileNames = Sets.newHashSet();
|
private Set<String> mFileNames = new HashSet<>();
|
||||||
|
|
||||||
public static <T extends ContentProvider> T providerWithRenamedContext(
|
public static <T extends ContentProvider> T providerWithRenamedContext(
|
||||||
Class<T> contentProvider, Context c, String filePrefix)
|
Class<T> contentProvider, Context c, String filePrefix)
|
||||||
@@ -237,10 +241,14 @@ public class RenamingDelegatingContext extends ContextWrapper {
|
|||||||
Log.w("RenamingDelegatingContext", "Unable to create cache directory");
|
Log.w("RenamingDelegatingContext", "Unable to create cache directory");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
FileUtils.setPermissions(
|
try {
|
||||||
mCacheDir.getPath(),
|
// Give the directory all possible permissions.
|
||||||
FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
|
Files.setPosixFilePermissions(mCacheDir.toPath(),
|
||||||
-1, -1);
|
EnumSet.allOf(PosixFilePermission.class));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e("RenamingDelegatingContext",
|
||||||
|
"Could not set permissions of test cacheDir", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mCacheDir;
|
return mCacheDir;
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
package android.test;
|
package android.test;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
@@ -44,7 +43,7 @@ public class TestCaseUtil {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<String> getTestCaseNames(Test test, boolean flatten) {
|
public static List<String> getTestCaseNames(Test test, boolean flatten) {
|
||||||
List<Test> tests = (List<Test>) getTests(test, flatten);
|
List<Test> tests = (List<Test>) getTests(test, flatten);
|
||||||
List<String> testCaseNames = Lists.newArrayList();
|
List<String> testCaseNames = new ArrayList<>();
|
||||||
for (Test aTest : tests) {
|
for (Test aTest : tests) {
|
||||||
testCaseNames.add(getTestName(aTest));
|
testCaseNames.add(getTestName(aTest));
|
||||||
}
|
}
|
||||||
@@ -57,7 +56,7 @@ public class TestCaseUtil {
|
|||||||
|
|
||||||
private static List<? extends Test> getTests(Test test, boolean flatten,
|
private static List<? extends Test> getTests(Test test, boolean flatten,
|
||||||
Set<Class<?>> seen) {
|
Set<Class<?>> seen) {
|
||||||
List<Test> testCases = Lists.newArrayList();
|
List<Test> testCases = new ArrayList<>();
|
||||||
if (test != null) {
|
if (test != null) {
|
||||||
|
|
||||||
Test workingTest = null;
|
Test workingTest = null;
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import junit.framework.TestSuite;
|
|||||||
import junit.framework.TestListener;
|
import junit.framework.TestListener;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestResult;
|
import junit.framework.TestResult;
|
||||||
import com.google.android.collect.Lists;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support class that actually runs a test. Android uses this class,
|
* Support class that actually runs a test. Android uses this class,
|
||||||
@@ -54,7 +53,7 @@ public class TestRunner implements PerformanceTestCase.Intermediates {
|
|||||||
|
|
||||||
private int mMode = REGRESSION;
|
private int mMode = REGRESSION;
|
||||||
|
|
||||||
private List<Listener> mListeners = Lists.newArrayList();
|
private List<Listener> mListeners = new ArrayList<>();
|
||||||
private int mPassed;
|
private int mPassed;
|
||||||
private int mFailed;
|
private int mFailed;
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ import android.content.IContentProvider;
|
|||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import com.google.android.collect.Maps;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +66,7 @@ public class MockContentResolver extends ContentResolver {
|
|||||||
*/
|
*/
|
||||||
public MockContentResolver(Context context) {
|
public MockContentResolver(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mProviders = Maps.newHashMap();
|
mProviders = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import android.test.AndroidTestRunner;
|
|||||||
import android.test.TestCaseUtil;
|
import android.test.TestCaseUtil;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.android.internal.util.Predicate;
|
import com.android.internal.util.Predicate;
|
||||||
import com.google.android.collect.Lists;
|
|
||||||
import static android.test.suitebuilder.TestGrouping.SORT_BY_FULLY_QUALIFIED_NAME;
|
import static android.test.suitebuilder.TestGrouping.SORT_BY_FULLY_QUALIFIED_NAME;
|
||||||
import static android.test.suitebuilder.TestPredicates.REJECT_SUPPRESSED;
|
import static android.test.suitebuilder.TestPredicates.REJECT_SUPPRESSED;
|
||||||
|
|
||||||
@@ -69,7 +68,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.setClassLoader(classLoader);
|
||||||
this.testCases = Lists.newArrayList();
|
this.testCases = new ArrayList<>();
|
||||||
addRequirements(REJECT_SUPPRESSED);
|
addRequirements(REJECT_SUPPRESSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ package android.test;
|
|||||||
import android.test.mock.MockContext;
|
import android.test.mock.MockContext;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
@@ -140,7 +139,7 @@ public class AndroidTestRunnerTest extends TestCase {
|
|||||||
public void testSetTestClassWithTestSuiteProvider() throws Exception {
|
public void testSetTestClassWithTestSuiteProvider() throws Exception {
|
||||||
mAndroidTestRunner.setTestClassName(SampleTestSuiteProvider.class.getName(), null);
|
mAndroidTestRunner.setTestClassName(SampleTestSuiteProvider.class.getName(), null);
|
||||||
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
|
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
|
||||||
List<String> testNames = Lists.newArrayList();
|
List<String> testNames = new ArrayList<>();
|
||||||
for (TestCase testCase : testCases) {
|
for (TestCase testCase : testCases) {
|
||||||
testNames.add(testCase.getName());
|
testNames.add(testCase.getName());
|
||||||
}
|
}
|
||||||
@@ -152,7 +151,7 @@ public class AndroidTestRunnerTest extends TestCase {
|
|||||||
public void testSetTestClassWithTestSuite() throws Exception {
|
public void testSetTestClassWithTestSuite() throws Exception {
|
||||||
mAndroidTestRunner.setTestClassName(SampleTestSuite.class.getName(), null);
|
mAndroidTestRunner.setTestClassName(SampleTestSuite.class.getName(), null);
|
||||||
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
|
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
|
||||||
List<String> testNames = Lists.newArrayList();
|
List<String> testNames = new ArrayList<>();
|
||||||
for (TestCase testCase : testCases) {
|
for (TestCase testCase : testCases) {
|
||||||
testNames.add(testCase.getName());
|
testNames.add(testCase.getName());
|
||||||
}
|
}
|
||||||
@@ -163,7 +162,7 @@ public class AndroidTestRunnerTest extends TestCase {
|
|||||||
String testMethodName = "testTwo";
|
String testMethodName = "testTwo";
|
||||||
mAndroidTestRunner.setTestClassName(TwoTestTestCase.class.getName(), testMethodName);
|
mAndroidTestRunner.setTestClassName(TwoTestTestCase.class.getName(), testMethodName);
|
||||||
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
|
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
|
||||||
List<String> testNames = Lists.newArrayList();
|
List<String> testNames = new ArrayList<>();
|
||||||
for (TestCase testCase : testCases) {
|
for (TestCase testCase : testCases) {
|
||||||
testNames.add(testCase.getName());
|
testNames.add(testCase.getName());
|
||||||
}
|
}
|
||||||
@@ -255,7 +254,7 @@ public class AndroidTestRunnerTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class TestListenerStub implements TestListener {
|
private static class TestListenerStub implements TestListener {
|
||||||
List<String> testNames = Lists.newArrayList();
|
List<String> testNames = new ArrayList<>();
|
||||||
|
|
||||||
public void addError(Test test, Throwable t) {
|
public void addError(Test test, Throwable t) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user