Build fix
Use getInstrumentation().getTargetContext() to get test app context.
Bug:23642167
Change-Id: I41d6ad5c2cdc2f0668d748b713ff899c8c56ebdc
diff --git a/tests/src/com/android/contacts/common/model/account/AccountTypeTest.java b/tests/src/com/android/contacts/common/model/account/AccountTypeTest.java
index 02f5446..8dc7df7 100644
--- a/tests/src/com/android/contacts/common/model/account/AccountTypeTest.java
+++ b/tests/src/com/android/contacts/common/model/account/AccountTypeTest.java
@@ -34,7 +34,7 @@
// In this test we use the test package itself as an external package.
final String packageName = getInstrumentation().getContext().getPackageName();
- final Context c = getContext();
+ final Context c = getInstrumentation().getTargetContext();
final String DEFAULT = "ABC";
// Package name null, resId -1, use the default
@@ -60,7 +60,7 @@
*/
public void testGetInviteContactActionLabel() {
final String packageName = getInstrumentation().getContext().getPackageName();
- final Context c = getContext();
+ final Context c = getInstrumentation().getTargetContext();
final int externalResID = R.string.test_string;
@@ -104,7 +104,8 @@
}
private int compareDisplayLabel(AccountType lhs, AccountType rhs) {
- return new AccountType.DisplayLabelComparator(getContext()).compare(lhs, rhs);
+ return new AccountType.DisplayLabelComparator(
+ getInstrumentation().getTargetContext()).compare(lhs, rhs);
}
private class AccountTypeForDisplayLabelTest extends AccountType {
diff --git a/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java b/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
index 60d9c4a..932dddc 100644
--- a/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
+++ b/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
@@ -47,7 +47,7 @@
@SmallTest
public class ExternalAccountTypeTest extends InstrumentationTestCase {
public void testResolveExternalResId() {
- final Context c = getContext();
+ final Context c = getInstrumentation().getTargetContext();
// In this test we use the test package itself as an external package.
final String packageName = getInstrumentation().getContext().getPackageName();
@@ -72,7 +72,7 @@
* Initialize with an invalid package name and see if type will be initialized, but empty.
*/
public void testNoPackage() {
- final ExternalAccountType type = new ExternalAccountType(getContext(),
+ final ExternalAccountType type = new ExternalAccountType(getInstrumentation().getTargetContext(),
"!!!no such package name!!!", false);
assertTrue(type.isInitialized());
}
@@ -81,7 +81,7 @@
* Initialize with the test package itself and see if EditSchema is correctly parsed.
*/
public void testEditSchema() {
- final ExternalAccountType type = new ExternalAccountType(getContext(),
+ final ExternalAccountType type = new ExternalAccountType(getInstrumentation().getTargetContext(),
getInstrumentation().getContext().getPackageName(), false);
assertTrue(type.isInitialized());
@@ -107,7 +107,7 @@
* {@link com.android.contacts.common.model.account.FallbackAccountType}.
*/
public void testEditSchema_fallback() {
- final ExternalAccountType type = new ExternalAccountType(getContext(),
+ final ExternalAccountType type = new ExternalAccountType(getInstrumentation().getTargetContext(),
getInstrumentation().getContext().getPackageName(), false,
getInstrumentation().getContext().getResources().getXml(R.xml.contacts_fallback)
);
@@ -117,7 +117,7 @@
// Create a fallback type with the same resource package name, and compare all the data
// kinds to its.
final AccountType reference = FallbackAccountType.createWithPackageNameForTest(
- getContext(), type.resourcePackageName);
+ getInstrumentation().getTargetContext(), type.resourcePackageName);
assertsDataKindEquals(reference.getSortedDataKinds(), type.getSortedDataKinds());
}
@@ -136,7 +136,7 @@
}
private void checkEditSchema_mustHaveChecks(int xmlResId, boolean expectInitialized) {
- final ExternalAccountType type = new ExternalAccountType(getContext(),
+ final ExternalAccountType type = new ExternalAccountType(getInstrumentation().getTargetContext(),
getInstrumentation().getContext().getPackageName(), false,
getInstrumentation().getContext().getResources().getXml(xmlResId)
);
@@ -148,7 +148,7 @@
* Initialize with "contacts_readonly.xml" and see if all data kinds are correctly registered.
*/
public void testReadOnlyDefinition() {
- final ExternalAccountType type = new ExternalAccountType(getContext(),
+ final ExternalAccountType type = new ExternalAccountType(getInstrumentation().getTargetContext(),
getInstrumentation().getContext().getPackageName(), false,
getInstrumentation().getContext().getResources().getXml(R.xml.contacts_readonly)
);