summaryrefslogtreecommitdiff
path: root/tests/src/com
diff options
context:
space:
mode:
authorMarcus Hagerott <mhagerott@google.com>2016-12-13 14:39:16 -0800
committerMarcus Hagerott <mhagerott@google.com>2016-12-13 14:41:16 -0800
commitf0d26c5ffe04f7114cce73a7ffff2ee7b92eb15a (patch)
treed8310eeca65d406f091751632b1c3791912e93d2 /tests/src/com
parentb2504c7327f3c43e6bc532a834766df9c4a3fdb0 (diff)
downloadContacts-f0d26c5ffe04f7114cce73a7ffff2ee7b92eb15a.tar.gz
Fix DynamicShortcutsTests
Broke by I91e8070470ed6f7a1518d3c70264977b15230ec4 Test: ran unit tests Bug 33546024 Change-Id: I8e669e5092fb73736fce7ee7338fd4a9311f0ef7
Diffstat (limited to 'tests/src/com')
-rw-r--r--tests/src/com/android/contacts/DynamicShortcutsTests.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/tests/src/com/android/contacts/DynamicShortcutsTests.java b/tests/src/com/android/contacts/DynamicShortcutsTests.java
index 34cd8c41d..2945663ab 100644
--- a/tests/src/com/android/contacts/DynamicShortcutsTests.java
+++ b/tests/src/com/android/contacts/DynamicShortcutsTests.java
@@ -32,7 +32,6 @@ import android.support.test.filters.SdkSuppress;
import android.test.AndroidTestCase;
import android.test.mock.MockContentResolver;
import android.test.suitebuilder.annotation.SmallTest;
-import android.test.suitebuilder.annotation.Suppress;
import com.android.contacts.common.test.mocks.MockContentProvider;
@@ -42,6 +41,7 @@ import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.mockito.ArgumentCaptor;
+import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -52,7 +52,6 @@ import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@TargetApi(Build.VERSION_CODES.N_MR1)
@@ -120,10 +119,10 @@ public class DynamicShortcutsTests extends AndroidTestCase {
assertEquals("123456789…", shortcut.getLongLabel());
}
- public void test_updatePinned_disablesShortcutsForRemovedContacts() {
+ public void test_updatePinned_disablesShortcutsForRemovedContacts() throws Exception {
final ShortcutManager mockShortcutManager = mock(ShortcutManager.class);
when(mockShortcutManager.getPinnedShortcuts()).thenReturn(
- Collections.singletonList(shortcutFor(1l, "key1", "name1")));
+ Collections.singletonList(makeDynamic(shortcutFor(1l, "key1", "name1"))));
final DynamicShortcuts sut = createDynamicShortcuts(emptyResolver(), mockShortcutManager);
@@ -133,13 +132,13 @@ public class DynamicShortcutsTests extends AndroidTestCase {
eq(Collections.singletonList("key1")), anyString());
}
- public void test_updatePinned_updatesExistingShortcutsWithMatchingKeys() {
+ public void test_updatePinned_updatesExistingShortcutsWithMatchingKeys() throws Exception {
final ShortcutManager mockShortcutManager = mock(ShortcutManager.class);
when(mockShortcutManager.getPinnedShortcuts()).thenReturn(
Arrays.asList(
- shortcutFor(1l, "key1", "name1"),
- shortcutFor(2l, "key2", "name2"),
- shortcutFor(3l, "key3", "name3")
+ makeDynamic(shortcutFor(1l, "key1", "name1")),
+ makeDynamic(shortcutFor(2l, "key2", "name2")),
+ makeDynamic(shortcutFor(3l, "key3", "name3"))
));
final DynamicShortcuts sut = createDynamicShortcuts(resolverWithExpectedQueries(
@@ -350,6 +349,15 @@ public class DynamicShortcutsTests extends AndroidTestCase {
return queryResult(DynamicShortcuts.PROJECTION, values);
}
+ // Ugly hack because the API is hidden. Alternative is to actually set the shortcut on the real
+ // ShortcutManager but this seems simpler for now.
+ private ShortcutInfo makeDynamic(ShortcutInfo shortcutInfo) throws Exception {
+ final Method addFlagsMethod = ShortcutInfo.class.getMethod("addFlags", int.class);
+ // 1 = FLAG_DYNAMIC
+ addFlagsMethod.invoke(shortcutInfo, 1);
+ return shortcutInfo;
+ }
+
private Cursor queryResult(String[] columns, Object... values) {
MatrixCursor result = new MatrixCursor(new String[] {
Contacts._ID, Contacts.LOOKUP_KEY,