diff options
Diffstat (limited to 'tests/src/com/android/dialer/filterednumber')
6 files changed, 0 insertions, 740 deletions
diff --git a/tests/src/com/android/dialer/filterednumber/BlockedNumbersAutoMigratorTest.java b/tests/src/com/android/dialer/filterednumber/BlockedNumbersAutoMigratorTest.java deleted file mode 100644 index 505855528..000000000 --- a/tests/src/com/android/dialer/filterednumber/BlockedNumbersAutoMigratorTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) 2016 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.dialer.filterednumber; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.test.AndroidTestCase; - -import com.android.contacts.common.compat.CompatUtils; -import com.android.dialer.compat.FilteredNumberCompat; -import com.android.dialer.database.FilteredNumberAsyncQueryHandler; -import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -public class BlockedNumbersAutoMigratorTest extends AndroidTestCase { - - private static final String HAS_CHECKED_AUTO_MIGRATE_KEY_FOR_TEST = "checkedAutoMigrateForTest"; - - @Mock - private FilteredNumberAsyncQueryHandler mockQueryHandler; - - private SharedPreferences sharedPreferences; - - private BlockedNumbersAutoMigrator blockedNumbersAutoMigrator; - - @Override - public void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - FilteredNumberCompat.setContextForTest(getContext()); - FilteredNumberCompat.setHasMigratedToNewBlocking(false); - - sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - // SharedPreference state isn't cleaned up between each test automatically, clear it now - sharedPreferences.edit().clear().apply(); - - blockedNumbersAutoMigrator = new BlockedNumbersAutoMigrator(sharedPreferences, - mockQueryHandler); - } - - public void testConstructor_NullSharedPreferences() { - try { - new BlockedNumbersAutoMigrator(null, mockQueryHandler); - fail(); - } catch (NullPointerException e) { - } - } - - public void testConstructor_NullQueryHandler() { - try { - new BlockedNumbersAutoMigrator(sharedPreferences, null); - fail(); - } catch (NullPointerException e) { - } - } - - public void testAutoMigrate_M() { - if (CompatUtils.isNCompatible()) { - return; - } - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler, never()).hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - } - - public void testAutoMigrate_AlreadyMigrated() { - if (!CompatUtils.isNCompatible()) { - return; - } - FilteredNumberCompat.setHasMigratedToNewBlocking(true); - - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler, never()).hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - } - - public void testAutoMigrate_AlreadyChecked() { - if (!CompatUtils.isNCompatible()) { - return; - } - sharedPreferences.edit() - .putBoolean(HAS_CHECKED_AUTO_MIGRATE_KEY_FOR_TEST, true) - .apply(); - - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler, never()).hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - } - - public void testAutoMigrate_HasNumbers() { - if (!CompatUtils.isNCompatible()) { - return; - } - setupFilteredNumberHasBlockedNumbersExpectation(true); - - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler).hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - assertFalse(FilteredNumberCompat.hasMigratedToNewBlocking()); - } - - public void testAutoMigrate_HasNumbers_MultipleCalls() { - if (!CompatUtils.isNCompatible()) { - return; - } - setupFilteredNumberHasBlockedNumbersExpectation(true); - - blockedNumbersAutoMigrator.autoMigrate(); - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler, times(1)) - .hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - assertFalse(FilteredNumberCompat.hasMigratedToNewBlocking()); - } - - public void testAutoMigrate_NoNumbers() { - if (!CompatUtils.isNCompatible()) { - return; - } - setupFilteredNumberHasBlockedNumbersExpectation(false); - - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler).hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - assertTrue(FilteredNumberCompat.hasMigratedToNewBlocking()); - } - - public void testAutoMigrate_NoNumbers_MultipleCalls() { - if (!CompatUtils.isNCompatible()) { - return; - } - setupFilteredNumberHasBlockedNumbersExpectation(false); - - blockedNumbersAutoMigrator.autoMigrate(); - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler, times(1)) - .hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - assertTrue(FilteredNumberCompat.hasMigratedToNewBlocking()); - } - - - public void testAutoMigrate_SimulateClearingAppData() { - if (!CompatUtils.isNCompatible()) { - return; - } - setupFilteredNumberHasBlockedNumbersExpectation(true); - - blockedNumbersAutoMigrator.autoMigrate(); - - // Clearing app data removes the sharedPreferences and all of the blocked numbers - sharedPreferences.edit().clear().apply(); - setupFilteredNumberHasBlockedNumbersExpectation(false); - - blockedNumbersAutoMigrator.autoMigrate(); - - verify(mockQueryHandler, times(2)) - .hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - assertTrue(FilteredNumberCompat.hasMigratedToNewBlocking()); - } - - /* - * Sets up the {@link #mockQueryHandler} to call the {@link OnHasBlockedNumbersListener} with - * the given hasBlockedNumbers value as the parameter, when - * {@link FilteredNumberAsyncQueryHandler#hasBlockedNumbers} is called. - */ - private void setupFilteredNumberHasBlockedNumbersExpectation(final boolean hasBlockedNumbers) { - doAnswer(new Answer<Void>() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - ((OnHasBlockedNumbersListener) invocation.getArguments()[0]) - .onHasBlockedNumbers(hasBlockedNumbers); - return null; - } - }).when(mockQueryHandler).hasBlockedNumbers(any(OnHasBlockedNumbersListener.class)); - } -} diff --git a/tests/src/com/android/dialer/filterednumber/BlockedNumbersFragmentInstrumentationTest.java b/tests/src/com/android/dialer/filterednumber/BlockedNumbersFragmentInstrumentationTest.java deleted file mode 100644 index ea4c51e21..000000000 --- a/tests/src/com/android/dialer/filterednumber/BlockedNumbersFragmentInstrumentationTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2016 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.dialer.filterednumber; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; - -import android.test.ActivityInstrumentationTestCase2; -import android.view.View; - -import com.android.contacts.common.compat.CompatUtils; -import com.android.dialer.R; -import com.android.dialer.compat.FilteredNumberCompat; -import com.android.dialer.filterednumber.BlockedNumbersMigrator.Listener; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -/** - * Instrumentation tests for {@link BlockedNumbersFragment}. Note for these tests to work properly, - * the device's screen must be on. - */ -public class BlockedNumbersFragmentInstrumentationTest extends - ActivityInstrumentationTestCase2<BlockedNumbersSettingsActivity> { - - private static final String FRAGMENT_TAG = "blocked_management"; - - private BlockedNumbersFragment blockedNumbersFragment; - @Mock private BlockedNumbersMigrator blockedNumbersMigrator; - - public BlockedNumbersFragmentInstrumentationTest() { - super(BlockedNumbersSettingsActivity.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - FilteredNumberCompat.setIsEnabledForTest(true); - blockedNumbersFragment = new BlockedNumbersFragment(); - blockedNumbersFragment.setBlockedNumbersMigratorForTest(blockedNumbersMigrator); - getActivity().getFragmentManager().beginTransaction() - .replace(R.id.blocked_numbers_activity_container, blockedNumbersFragment, FRAGMENT_TAG) - .commit(); - getInstrumentation().waitForIdleSync(); - } - - public void testMigrationPromo_NotShown_M() { - if (CompatUtils.isNCompatible()) { - return; - } - assertEquals(View.GONE, blockedNumbersFragment.migratePromoView.getVisibility()); - } - - public void testMigrationPromo_Shown_N() { - if (!CompatUtils.isNCompatible()) { - return; - } - assertEquals(View.VISIBLE, blockedNumbersFragment.migratePromoView.getVisibility()); - } - - public void testOnClick_Migrate() { - if (!CompatUtils.isNCompatible()) { - return; - } - - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - blockedNumbersFragment.getListView().findViewById(R.id.migrate_promo_allow_button) - .performClick(); - } - }); - getInstrumentation().waitForIdleSync(); - assertFalse(blockedNumbersFragment.getListView().findViewById(R.id.migrate_promo_allow_button) - .isEnabled()); - verify(blockedNumbersMigrator).migrate(any(Listener.class)); - } -} diff --git a/tests/src/com/android/dialer/filterednumber/BlockedNumbersMigratorTest.java b/tests/src/com/android/dialer/filterednumber/BlockedNumbersMigratorTest.java deleted file mode 100644 index 565c206d8..000000000 --- a/tests/src/com/android/dialer/filterednumber/BlockedNumbersMigratorTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2016 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.dialer.filterednumber; - -import android.content.ContentUris; -import android.content.ContentValues; -import android.provider.BlockedNumberContract; -import android.provider.BlockedNumberContract.BlockedNumbers; -import android.test.AndroidTestCase; -import android.test.mock.MockContentResolver; - -import com.android.contacts.common.compat.CompatUtils; -import com.android.contacts.common.test.mocks.MockContentProvider; -import com.android.dialer.compat.FilteredNumberCompat; -import com.android.dialer.database.FilteredNumberContract; -import com.android.dialer.database.FilteredNumberContract.FilteredNumber; -import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -public class BlockedNumbersMigratorTest extends AndroidTestCase { - - private static final String NUMBER = "6502530000"; - private static final String NUMBER1 = "6502530001"; - private static final String NUMBER2 = "6502530002"; - - @Mock private BlockedNumbersMigrator.Listener mListener; - private final MockContentResolver mContentResolver = new MockContentResolver(); - private final MockContentProvider mContentProvider = new MockContentProvider(); - private BlockedNumbersMigrator mMigrator; - - @Override - public void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - FilteredNumberCompat.setIsEnabledForTest(true); - mContentResolver.addProvider(FilteredNumberContract.AUTHORITY, mContentProvider); - mContentResolver.addProvider(BlockedNumberContract.AUTHORITY, mContentProvider); - mMigrator = new BlockedNumbersMigrator(mContentResolver); - } - - public void testConstructor_NullContentResolver() { - try { - new BlockedNumbersMigrator(null); - fail(); - } catch (NullPointerException e) {} - } - - public void testMigrate_M() { - if (CompatUtils.isNCompatible()) { - return; - } - assertFalse(mMigrator.migrate(mListener)); - } - - public void testMigrate_N_Disabled() { - if (!CompatUtils.isNCompatible()) { - return; - } - FilteredNumberCompat.setIsEnabledForTest(false); - assertFalse(mMigrator.migrate(mListener)); - } - - public void testMigrate_N_NullListener() { - if (!CompatUtils.isNCompatible()) { - return; - } - try { - mMigrator.migrate(null); - fail(); - } catch (NullPointerException e) {} - } - - public void testMigrate_N() throws InterruptedException { - if (!CompatUtils.isNCompatible()) { - return; - } - mContentProvider.expectQuery(FilteredNumber.CONTENT_URI) - .withProjection(FilteredNumberColumns.NUMBER).returnRow(NUMBER).returnRow(NUMBER1) - .returnRow(NUMBER2); - - setUpNewBlockedNumberExpectations(mContentProvider, NUMBER, 0); - setUpNewBlockedNumberExpectations(mContentProvider, NUMBER1, 1); - setUpNewBlockedNumberExpectations(mContentProvider, NUMBER2, 2); - - MigrationListener listener = new MigrationListener(); - assertTrue(mMigrator.migrate(listener)); - listener.waitForCallback(); - assertTrue(FilteredNumberCompat.hasMigratedToNewBlocking()); - mContentProvider.verify(); - } - - public void testMigrate_N_AlreadyBlocked() throws InterruptedException { - if (!CompatUtils.isNCompatible()) { - return; - } - mContentProvider.expectQuery(FilteredNumber.CONTENT_URI) - .withProjection(FilteredNumberColumns.NUMBER).returnRow(NUMBER); - mContentProvider.expectQuery(BlockedNumbers.CONTENT_URI) - .withProjection(BlockedNumbers.COLUMN_ID) - .withSelection(BlockedNumbers.COLUMN_ORIGINAL_NUMBER + " = ?", NUMBER).returnRow(0); - // No expectation for insert into BlockedNumbers.CONTENT_URI because it's already there - - MigrationListener listener = new MigrationListener(); - assertTrue(mMigrator.migrate(listener)); - listener.waitForCallback(); - assertTrue(FilteredNumberCompat.hasMigratedToNewBlocking()); - mContentProvider.verify(); - } - - private void setUpNewBlockedNumberExpectations(MockContentProvider contentProvider, - String number, int returnId) { - contentProvider.expectQuery(BlockedNumbers.CONTENT_URI) - .withProjection(BlockedNumbers.COLUMN_ID) - .withSelection(BlockedNumbers.COLUMN_ORIGINAL_NUMBER + " = ?", number).returnEmptyCursor(); - contentProvider.expectInsert(BlockedNumbers.CONTENT_URI, - createBlockedNumberInsertValues(number), - ContentUris.withAppendedId(BlockedNumbers.CONTENT_URI, returnId)); - } - - private ContentValues createBlockedNumberInsertValues(String number) { - ContentValues values = new ContentValues(); - values.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, number); - return values; - } - - private static class MigrationListener implements BlockedNumbersMigrator.Listener { - - private final CountDownLatch mOnCompleteCalled = new CountDownLatch(1); - - @Override - public void onComplete() { - mOnCompleteCalled.countDown(); - } - - public void waitForCallback() throws InterruptedException { - if (!mOnCompleteCalled.await(5000, TimeUnit.MILLISECONDS)) { - throw new IllegalStateException("Waiting on callback timed out."); - } - } - } -} diff --git a/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java b/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java deleted file mode 100644 index d496b1845..000000000 --- a/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2015 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.dialer.filterednumber; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; - -import android.content.Context; -import android.preference.PreferenceManager; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import com.android.contacts.common.compat.CompatUtils; -import com.android.contacts.common.test.mocks.ContactsMockContext; -import com.android.contacts.common.test.mocks.MockContentProvider.Query; -import com.android.dialer.compat.FilteredNumberCompat; -import com.android.dialer.database.FilteredNumberContract; -import com.android.dialer.database.FilteredNumberContract.FilteredNumber; -import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; - -@SmallTest -public class FilteredNumbersUtilTest extends AndroidTestCase { - - private static final String COUNTRY_ISO = "US"; - - // Wed Nov 11 2015 15:00:00 - private static final long EARLIER_TIME = 1447282800000L; - - // Wed Nov 11 2015 15:01:40 - private static final long LATER_TIME = 1447282900000L; - - private static final String[] FILTERED_NUMBER_PROJECTION = new String[] { - FilteredNumberColumns.CREATION_TIME }; - - private static final String NORMALIZED_NUMBER = "+16503903411"; - - private static final long NULL_CREATION_TIME = -1; - - private ContactsMockContext mContext; - - @Override - public void setUp() throws Exception { - super.setUp(); - mContext = new ContactsMockContext(getContext(), FilteredNumberContract.AUTHORITY); - - // Reset whether an emergency number was dialed - PreferenceManager.getDefaultSharedPreferences(mContext) - .edit() - .putLong(FilteredNumbersUtil.LAST_EMERGENCY_CALL_MS_PREF_KEY, 0) - .apply(); - } - - public void testShouldBlockVoicemail_NotBlocked() { - setupShouldBlockVoicemailQuery(NULL_CREATION_TIME); - assertFalse(FilteredNumbersUtil.shouldBlockVoicemail(mContext, NORMALIZED_NUMBER, - COUNTRY_ISO, EARLIER_TIME)); - } - - public void testShouldBlockVoicemail_BlockedBeforeVoicemail() { - setupShouldBlockVoicemailQuery(EARLIER_TIME); - assertTrue(FilteredNumbersUtil.shouldBlockVoicemail(mContext, NORMALIZED_NUMBER, - COUNTRY_ISO, LATER_TIME)); - } - - public void testShouldBlockVoicemail_BlockedAfterVoicemail() { - setupShouldBlockVoicemailQuery(LATER_TIME); - assertFalse(FilteredNumbersUtil.shouldBlockVoicemail(mContext, NORMALIZED_NUMBER, - COUNTRY_ISO, EARLIER_TIME)); - } - - public void testShouldBlockVoicemail_BlockedSameTimeAsVoicemail() { - setupShouldBlockVoicemailQuery(EARLIER_TIME); - assertTrue(FilteredNumbersUtil.shouldBlockVoicemail(mContext, NORMALIZED_NUMBER, - COUNTRY_ISO, EARLIER_TIME)); - } - - public void testShouldBlockVoicemail_BlockedInSameMinuteAsVoicemail() { - setupShouldBlockVoicemailQuery(EARLIER_TIME); - assertTrue(FilteredNumbersUtil.shouldBlockVoicemail(mContext, NORMALIZED_NUMBER, - COUNTRY_ISO, EARLIER_TIME + 30000)); - } - - public void testShouldBlockVoicemail_AfterEmergencyCall() { - // Just called emergency services - PreferenceManager.getDefaultSharedPreferences(mContext) - .edit() - .putLong(FilteredNumbersUtil.LAST_EMERGENCY_CALL_MS_PREF_KEY, - System.currentTimeMillis()) - .apply(); - assertFalse(FilteredNumbersUtil.shouldBlockVoicemail(mContext, NORMALIZED_NUMBER, - COUNTRY_ISO, 0)); - } - - public void testMaybeNotifyCallBlockingDisabled_Migrated() { - if (!CompatUtils.isNCompatible()) { - return; - } - FilteredNumberCompat.setIsEnabledForTest(true); - FilteredNumberCompat.setHasMigratedToNewBlocking(true); - Context mockContext = mock(Context.class); - - FilteredNumbersUtil.maybeNotifyCallBlockingDisabled(mockContext); - verifyZeroInteractions(mockContext); - } - - private void setupShouldBlockVoicemailQuery(long creationTimeMs) { - Query query = mContext.getContactsProvider().expectQuery(FilteredNumber.CONTENT_URI) - .withProjection(FILTERED_NUMBER_PROJECTION) - .withAnySelection() - .withAnySortOrder(); - if (creationTimeMs == NULL_CREATION_TIME) { - query.returnEmptyCursor(); - return; - } - query.returnRow(creationTimeMs); - } -} diff --git a/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentInstrumentationTest.java b/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentInstrumentationTest.java deleted file mode 100644 index 0bfa6bcb2..000000000 --- a/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentInstrumentationTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2016 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.dialer.filterednumber; - -import android.app.AlertDialog; -import android.app.DialogFragment; -import android.content.ContentResolver; -import android.content.DialogInterface; -import android.test.ActivityInstrumentationTestCase2; - -import com.android.dialer.DialtactsActivity; -import com.android.dialer.filterednumber.BlockedNumbersMigrator.Listener; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -/** - * Instrumentation tests for {@link MigrateBlockedNumbersDialogFragment}. Note for these tests to - * work properly, the device's screen must be on. - */ -public class MigrateBlockedNumbersDialogFragmentInstrumentationTest extends - ActivityInstrumentationTestCase2<DialtactsActivity> { - - private static final String SHOW_TAG = "ShowTag"; - - private BlockedNumbersMigrator mBlockedNumbersMigrator; - @Mock private Listener mListener; - private DialogFragment mMigrateDialogFragment; - - public MigrateBlockedNumbersDialogFragmentInstrumentationTest() { - super(DialtactsActivity.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - mBlockedNumbersMigrator = new SynchronousBlockedNumbersMigrator( - getActivity().getContentResolver()); - mMigrateDialogFragment = MigrateBlockedNumbersDialogFragment - .newInstance(mBlockedNumbersMigrator, mListener); - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mMigrateDialogFragment.show(getActivity().getFragmentManager(), SHOW_TAG); - } - }); - getInstrumentation().waitForIdleSync(); - } - - public void testDialogAppears() { - assertTrue(mMigrateDialogFragment.getDialog().isShowing()); - } - - public void testDialogPositiveButtonPress() { - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - ((AlertDialog) mMigrateDialogFragment.getDialog()) - .getButton(DialogInterface.BUTTON_POSITIVE).performClick(); - } - }); - getInstrumentation().waitForIdleSync(); - // Dialog was dismissed - assertNull(mMigrateDialogFragment.getDialog()); - } - - private static class SynchronousBlockedNumbersMigrator extends BlockedNumbersMigrator { - public SynchronousBlockedNumbersMigrator(ContentResolver contentResolver) { - super(contentResolver); - } - - @Override - public boolean migrate(BlockedNumbersMigrator.Listener listener) { - listener.onComplete(); - return true; - } - } -} diff --git a/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentTest.java b/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentTest.java deleted file mode 100644 index 1b419cee8..000000000 --- a/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2016 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.dialer.filterednumber; - -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; - -import com.android.dialer.filterednumber.BlockedNumbersMigrator.Listener; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - - -/** - * Unit tests for {@link MigrateBlockedNumbersDialogFragment} - */ -@SmallTest -public class MigrateBlockedNumbersDialogFragmentTest extends AndroidTestCase { - - @Mock private BlockedNumbersMigrator mBlockedNumbersMigrator; - @Mock private Listener mListener; - - @Override - public void setUp() throws Exception { - super.setUp(); - MockitoAnnotations.initMocks(this); - } - - public void testNewInstance_NullMigrator() { - try { - MigrateBlockedNumbersDialogFragment.newInstance(null, mListener); - fail(); - } catch (NullPointerException e) {} - } - - public void testNewInstance_NullListener() { - try { - MigrateBlockedNumbersDialogFragment.newInstance(mBlockedNumbersMigrator, null); - fail(); - } catch (NullPointerException e) {} - } - - public void testNewInstance_WithListener() { - assertNotNull(MigrateBlockedNumbersDialogFragment.newInstance(mBlockedNumbersMigrator, - mListener)); - } -} |