summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChiao Cheng <chiaocheng@google.com>2012-11-01 17:03:07 -0700
committerChiao Cheng <chiaocheng@google.com>2012-11-02 16:37:28 -0700
commitdabac3f99c85bd6af90681a774796748c2775beb (patch)
tree66a5d8ca2538c1a72a5c1a2dfc4f52830dc60d98 /tests
parentc8dd78c595cfaf9766e59a2df012b16d6c05b213 (diff)
downloadpackages_apps_Contacts-dabac3f99c85bd6af90681a774796748c2775beb.tar.gz
packages_apps_Contacts-dabac3f99c85bd6af90681a774796748c2775beb.tar.bz2
packages_apps_Contacts-dabac3f99c85bd6af90681a774796748c2775beb.zip
Move AccountTypeManager singleton out of app context.
Put singleton directly into AccountTypeManager class instead of pulling it from the custom context ContactsApplication class. Bug: 6993891 Change-Id: Icc1b9736dff8916407c923ceaebb7844fca3e097
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/contacts/activities/PeopleActivityTest.java17
-rw-r--r--tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java21
-rw-r--r--tests/src/com/android/contacts/list/ContactListItemViewTest.java138
-rw-r--r--tests/src/com/android/contacts/model/ContactLoaderTest.java10
-rw-r--r--tests/src/com/android/contacts/tests/mocks/ContactsAccountManagerMockContext.java47
5 files changed, 23 insertions, 210 deletions
diff --git a/tests/src/com/android/contacts/activities/PeopleActivityTest.java b/tests/src/com/android/contacts/activities/PeopleActivityTest.java
index cda7a574e..644c0a586 100644
--- a/tests/src/com/android/contacts/activities/PeopleActivityTest.java
+++ b/tests/src/com/android/contacts/activities/PeopleActivityTest.java
@@ -35,6 +35,9 @@ import android.widget.TextView;
import com.android.contacts.ContactsApplication;
import com.android.contacts.R;
import com.android.contacts.common.ContactPhotoManager;
+import com.android.contacts.common.test.mocks.ContactsMockContext;
+import com.android.contacts.common.test.mocks.MockContentProvider;
+import com.android.contacts.common.test.mocks.MockContentProvider.Query;
import com.android.contacts.detail.ContactDetailFragment;
import com.android.contacts.interactions.TestLoaderManager;
import com.android.contacts.list.ContactBrowseListFragment;
@@ -43,12 +46,8 @@ import com.android.contacts.model.account.AccountType;
import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.model.account.BaseAccountType;
import com.android.contacts.test.InjectedServices;
-import com.android.contacts.tests.mocks.ContactsAccountManagerMockContext;
-import com.android.contacts.common.test.mocks.ContactsMockContext;
import com.android.contacts.tests.mocks.MockAccountTypeManager;
import com.android.contacts.tests.mocks.MockContactPhotoManager;
-import com.android.contacts.common.test.mocks.MockContentProvider;
-import com.android.contacts.common.test.mocks.MockContentProvider.Query;
import com.android.contacts.tests.mocks.MockSharedPreferences;
import com.android.contacts.util.PhoneCapabilityTester;
@@ -87,7 +86,7 @@ public class PeopleActivityTest
@Override
public void setUp() {
- mContext = new ContactsAccountManagerMockContext(getInstrumentation().getTargetContext());
+ mContext = new ContactsMockContext(getInstrumentation().getTargetContext());
mContactsProvider = mContext.getContactsProvider();
mSettingsProvider = mContext.getSettingsProvider();
InjectedServices services = new InjectedServices();
@@ -104,11 +103,11 @@ public class PeopleActivityTest
accountType.accountType = TEST_ACCOUNT_TYPE;
AccountWithDataSet account = new AccountWithDataSet(TEST_ACCOUNT, TEST_ACCOUNT_TYPE, null);
-
- services.setSystemService(AccountTypeManager.ACCOUNT_TYPE_SERVICE,
- new MockAccountTypeManager(
- new AccountType[]{accountType}, new AccountWithDataSet[]{account}));
ContactsApplication.injectServices(services);
+
+ final MockAccountTypeManager mockManager = new MockAccountTypeManager(
+ new AccountType[] { accountType }, new AccountWithDataSet[] { account });
+ AccountTypeManager.setInstanceForTest(mockManager);
}
@Override
diff --git a/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java b/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java
index c8346881b..bf4e24b20 100644
--- a/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java
+++ b/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java
@@ -26,17 +26,16 @@ import android.test.suitebuilder.annotation.SmallTest;
import com.android.contacts.ContactsApplication;
import com.android.contacts.R;
+import com.android.contacts.common.test.FragmentTestActivity;
+import com.android.contacts.common.test.IntegrationTestUtils;
+import com.android.contacts.common.test.mocks.ContactsMockContext;
+import com.android.contacts.common.test.mocks.MockContentProvider;
+import com.android.contacts.common.test.mocks.MockContentProvider.Query;
import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.model.account.AccountType;
import com.android.contacts.model.account.BaseAccountType;
-import com.android.contacts.common.test.FragmentTestActivity;
import com.android.contacts.test.InjectedServices;
-import com.android.contacts.tests.mocks.ContactsAccountManagerMockContext;
-import com.android.contacts.common.test.mocks.ContactsMockContext;
import com.android.contacts.tests.mocks.MockAccountTypeManager;
-import com.android.contacts.common.test.mocks.MockContentProvider;
-import com.android.contacts.common.test.mocks.MockContentProvider.Query;
-import com.android.contacts.common.test.IntegrationTestUtils;
/**
* Tests for {@link ContactDeletionInteraction}.
@@ -80,7 +79,7 @@ public class ContactDeletionInteractionTest
mUtils = new IntegrationTestUtils(getInstrumentation());
mUtils.acquireScreenWakeLock(getInstrumentation().getTargetContext());
- mContext = new ContactsAccountManagerMockContext(getInstrumentation().getTargetContext());
+ mContext = new ContactsMockContext(getInstrumentation().getTargetContext());
InjectedServices services = new InjectedServices();
services.setContentResolver(mContext.getContentResolver());
@@ -99,11 +98,11 @@ public class ContactDeletionInteractionTest
}
};
writableAccountType.accountType = WRITABLE_ACCOUNT_TYPE;
-
- services.setSystemService(AccountTypeManager.ACCOUNT_TYPE_SERVICE,
- new MockAccountTypeManager(
- new AccountType[]{writableAccountType, readOnlyAccountType}, null));
ContactsApplication.injectServices(services);
+
+ final MockAccountTypeManager mockManager = new MockAccountTypeManager(
+ new AccountType[] { writableAccountType, readOnlyAccountType }, null);
+ AccountTypeManager.setInstanceForTest(mockManager);
mContactsProvider = mContext.getContactsProvider();
}
diff --git a/tests/src/com/android/contacts/list/ContactListItemViewTest.java b/tests/src/com/android/contacts/list/ContactListItemViewTest.java
deleted file mode 100644
index 09ac7680b..000000000
--- a/tests/src/com/android/contacts/list/ContactListItemViewTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.contacts.list;
-
-import android.database.Cursor;
-import android.database.MatrixCursor;
-import android.provider.ContactsContract;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.widget.TextView;
-
-import com.android.contacts.activities.PeopleActivity;
-import com.android.contacts.common.test.IntegrationTestUtils;
-import com.android.contacts.common.format.SpannedTestUtils;
-
-/**
- * Unit tests for {@link ContactListItemView}.
- *
- * It uses an {@link ActivityInstrumentationTestCase2} for {@link PeopleActivity} because we need
- * to have the style properly setup.
- */
-@LargeTest
-public class ContactListItemViewTest extends ActivityInstrumentationTestCase2<PeopleActivity> {
- /** The HTML code used to mark the start of the highlighted part. */
- private static final String START = "<font color =\"#33b5e5\">";
- /** The HTML code used to mark the end of the highlighted part. */
- private static final String END = "</font>";
-
- private IntegrationTestUtils mUtils;
-
- public ContactListItemViewTest() {
- super(PeopleActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- // This test requires that the screen be turned on.
- mUtils = new IntegrationTestUtils(getInstrumentation());
- mUtils.acquireScreenWakeLock(getInstrumentation().getTargetContext());
- }
-
- @Override
- protected void tearDown() throws Exception {
- mUtils.releaseScreenWakeLock();
- super.tearDown();
- }
-
- public void testShowDisplayName_Simple() {
- Cursor cursor = createCursor("John Doe", "Doe John");
- ContactListItemView view = createView();
-
- view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY);
-
- assertEquals(view.getNameTextView().getText().toString(), "John Doe");
- }
-
- public void testShowDisplayName_Unknown() {
- Cursor cursor = createCursor("", "");
- ContactListItemView view = createView();
-
- view.setUnknownNameText("unknown");
- view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY);
-
- assertEquals(view.getNameTextView().getText().toString(), "unknown");
- }
-
- public void testShowDisplayName_WithPrefix() {
- Cursor cursor = createCursor("John Doe", "Doe John");
- ContactListItemView view = createView();
-
- view.setHighlightedPrefix("DOE".toCharArray());
- view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_PRIMARY);
-
- CharSequence seq = view.getNameTextView().getText();
- assertEquals("John Doe", seq.toString());
- SpannedTestUtils.assertPrefixSpan(seq, 5, 7);
- }
-
- public void testShowDisplayName_WithPrefixReversed() {
- Cursor cursor = createCursor("John Doe", "Doe John");
- ContactListItemView view = createView();
-
- view.setHighlightedPrefix("DOE".toCharArray());
- view.showDisplayName(cursor, 0, ContactsContract.Preferences.DISPLAY_ORDER_ALTERNATIVE);
-
- CharSequence seq = view.getNameTextView().getText();
- assertEquals("John Doe", seq.toString());
- SpannedTestUtils.assertPrefixSpan(seq, 5, 7);
- }
-
- public void testSetSnippet_Prefix() {
- ContactListItemView view = createView();
- view.setHighlightedPrefix("TEST".toCharArray());
- view.setSnippet("This is a test");
-
- CharSequence seq = view.getSnippetView().getText();
-
- assertEquals("This is a test", seq.toString());
- SpannedTestUtils.assertPrefixSpan(seq, 10, 13);
- }
-
- /** Creates the view to be tested. */
- private ContactListItemView createView() {
- ContactListItemView view = new ContactListItemView(getActivity(), null);
- // Set the name view to use a Spannable to represent its content.
- view.getNameTextView().setText("", TextView.BufferType.SPANNABLE);
- return view;
- }
-
- /**
- * Creates a cursor containing a pair of values.
- *
- * @param name the name to insert in the first column of the cursor
- * @param alternateName the alternate name to insert in the second column of the cursor
- * @return the newly created cursor
- */
- private Cursor createCursor(String name, String alternateName) {
- MatrixCursor cursor = new MatrixCursor(new String[]{"Name", "AlternateName"});
- cursor.moveToFirst();
- cursor.addRow(new Object[]{name, alternateName});
- return cursor;
- }
-}
diff --git a/tests/src/com/android/contacts/model/ContactLoaderTest.java b/tests/src/com/android/contacts/model/ContactLoaderTest.java
index f1fb7aef9..2876e2a2b 100644
--- a/tests/src/com/android/contacts/model/ContactLoaderTest.java
+++ b/tests/src/com/android/contacts/model/ContactLoaderTest.java
@@ -28,26 +28,26 @@ import android.provider.ContactsContract.StatusUpdates;
import android.test.LoaderTestCase;
import android.test.suitebuilder.annotation.LargeTest;
+import com.android.contacts.common.test.mocks.ContactsMockContext;
+import com.android.contacts.common.test.mocks.MockContentProvider;
import com.android.contacts.model.account.AccountType;
import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.model.account.BaseAccountType;
import com.android.contacts.test.InjectedServices;
-import com.android.contacts.tests.mocks.ContactsAccountManagerMockContext;
import com.android.contacts.tests.mocks.MockAccountTypeManager;
-import com.android.contacts.common.test.mocks.MockContentProvider;
/**
* Runs ContactLoader tests for the the contact-detail and editor view.
*/
@LargeTest
public class ContactLoaderTest extends LoaderTestCase {
- private ContactsAccountManagerMockContext mMockContext;
+ private ContactsMockContext mMockContext;
private MockContentProvider mContactsProvider;
@Override
protected void setUp() throws Exception {
super.setUp();
- mMockContext = new ContactsAccountManagerMockContext(getContext());
+ mMockContext = new ContactsMockContext(getContext());
mContactsProvider = mMockContext.getContactsProvider();
InjectedServices services = new InjectedServices();
@@ -62,7 +62,7 @@ public class ContactLoaderTest extends LoaderTestCase {
AccountWithDataSet account =
new AccountWithDataSet("mockAccountName", "mockAccountType", null);
- mMockContext.setMockAccountTypeManager(
+ AccountTypeManager.setInstanceForTest(
new MockAccountTypeManager(
new AccountType[]{accountType}, new AccountWithDataSet[]{account}));
}
diff --git a/tests/src/com/android/contacts/tests/mocks/ContactsAccountManagerMockContext.java b/tests/src/com/android/contacts/tests/mocks/ContactsAccountManagerMockContext.java
deleted file mode 100644
index c0ba9d395..000000000
--- a/tests/src/com/android/contacts/tests/mocks/ContactsAccountManagerMockContext.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.contacts.tests.mocks;
-
-import android.content.Context;
-
-import com.android.contacts.common.test.mocks.ContactsMockContext;
-import com.android.contacts.model.AccountTypeManager;
-
-/**
- * A ContactsMockContext with an additional mock AccountTypeManager.
- */
-public class ContactsAccountManagerMockContext extends ContactsMockContext {
-
- private MockAccountTypeManager mMockAccountTypeManager;
-
-
- public ContactsAccountManagerMockContext(Context base) {
- super(base);
- }
-
- public void setMockAccountTypeManager(MockAccountTypeManager mockAccountTypeManager) {
- mMockAccountTypeManager = mockAccountTypeManager;
- }
-
- @Override
- public Object getSystemService(String name) {
- if (AccountTypeManager.ACCOUNT_TYPE_SERVICE.equals(name)) {
- return mMockAccountTypeManager;
- }
- return super.getSystemService(name);
- }
-}