Fixes tests on userdebug builds.
A number of tests are currently failing on userdebug builds because they
refer to methods that are used only in tests and proguard striped these
methods when building the application APK.
This change adds the VisibleForTesting annotation to all such methods.
Bug: 4901489
Bug: 4902483
Change-Id: Ic7c51ef5b77f4f2d2af39cdafbf8e2e37260644b
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 4b0bbaa..2ec1cbf 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -17,6 +17,7 @@
package com.android.contacts;
import com.android.contacts.util.DataStatus;
+import com.google.common.annotations.VisibleForTesting;
import android.content.ContentResolver;
import android.content.ContentUris;
@@ -238,7 +239,8 @@
return mUri;
}
- public long getId() {
+ @VisibleForTesting
+ /*package*/ long getId() {
return mId;
}
diff --git a/src/com/android/contacts/ContactsApplication.java b/src/com/android/contacts/ContactsApplication.java
index c925ec0..1c8c080 100644
--- a/src/com/android/contacts/ContactsApplication.java
+++ b/src/com/android/contacts/ContactsApplication.java
@@ -18,6 +18,7 @@
import com.android.contacts.model.AccountTypeManager;
import com.android.contacts.test.InjectedServices;
+import com.google.common.annotations.VisibleForTesting;
import android.app.Application;
import android.app.LoaderManager;
@@ -36,6 +37,7 @@
/**
* Overrides the system services with mocks for testing.
*/
+ @VisibleForTesting
public static void injectServices(InjectedServices services) {
sInjectedServices = services;
}
diff --git a/src/com/android/contacts/activities/CallLogActivity.java b/src/com/android/contacts/activities/CallLogActivity.java
index 13c3209..4ddf4d0 100644
--- a/src/com/android/contacts/activities/CallLogActivity.java
+++ b/src/com/android/contacts/activities/CallLogActivity.java
@@ -20,6 +20,7 @@
import com.android.contacts.R;
import com.android.contacts.calllog.CallLogFragment;
import com.android.internal.telephony.ITelephony;
+import com.google.common.annotations.VisibleForTesting;
import android.app.Activity;
import android.content.ActivityNotFoundException;
@@ -54,7 +55,8 @@
R.id.call_log_fragment);
}
- public CallLogFragment getFragment() {
+ @VisibleForTesting
+ /*package*/ CallLogFragment getFragment() {
return mFragment;
}
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index b3043d4..bcffd1c 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -1111,10 +1111,12 @@
}
}
+ @VisibleForTesting
public CallLogAdapter getAdapter() {
return mAdapter;
}
+ @VisibleForTesting
public String getVoiceMailNumber() {
return mVoiceMailNumber;
}
diff --git a/src/com/android/contacts/format/FormatUtils.java b/src/com/android/contacts/format/FormatUtils.java
index c4f4930..771656b 100644
--- a/src/com/android/contacts/format/FormatUtils.java
+++ b/src/com/android/contacts/format/FormatUtils.java
@@ -15,6 +15,8 @@
*/
package com.android.contacts.format;
+import com.google.common.annotations.VisibleForTesting;
+
import android.database.CharArrayBuffer;
import android.graphics.Typeface;
import android.text.SpannableString;
@@ -106,7 +108,8 @@
return text;
}
- public static void copyToCharArrayBuffer(String text, CharArrayBuffer buffer) {
+ @VisibleForTesting
+ /*package*/ static void copyToCharArrayBuffer(String text, CharArrayBuffer buffer) {
if (text != null) {
char[] data = buffer.data;
if (data == null || data.length < text.length()) {
diff --git a/src/com/android/contacts/format/PrefixHighlighter.java b/src/com/android/contacts/format/PrefixHighlighter.java
index 943dcb4..0bc67a6 100644
--- a/src/com/android/contacts/format/PrefixHighlighter.java
+++ b/src/com/android/contacts/format/PrefixHighlighter.java
@@ -16,7 +16,6 @@
package com.android.contacts.format;
-import android.database.CharArrayBuffer;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;
@@ -45,17 +44,6 @@
}
/**
- * Sets the text on the given text view, highlighting the word that matches the given prefix.
- *
- * @param view the view on which to set the text
- * @param text the text to use as the text
- * @param prefix the prefix to look for
- */
- public void setText(TextView view, CharArrayBuffer text, char[] prefix) {
- setText(view, FormatUtils.charArrayBufferToString(text), prefix);
- }
-
- /**
* Returns a CharSequence which highlights the given prefix if found in the given text.
*
* @param text the text to which to apply the highlight
diff --git a/src/com/android/contacts/interactions/TestLoaderManager.java b/src/com/android/contacts/interactions/TestLoaderManager.java
index db975ed..6c2d9e8 100644
--- a/src/com/android/contacts/interactions/TestLoaderManager.java
+++ b/src/com/android/contacts/interactions/TestLoaderManager.java
@@ -16,6 +16,8 @@
package com.android.contacts.interactions;
+import com.google.common.annotations.VisibleForTesting;
+
import android.app.Activity;
import android.app.LoaderManager;
import android.content.AsyncTaskLoader;
@@ -123,7 +125,8 @@
* If one of the loaders has already completed since the last call to {@link #reset()}, it will
* not wait for it to complete again.
*/
- public synchronized void waitForLoaders(int... loaderIds) {
+ @VisibleForTesting
+ /*package*/ synchronized void waitForLoaders(int... loaderIds) {
List<Loader<?>> loaders = new ArrayList<Loader<?>>(loaderIds.length);
for (int loaderId : loaderIds) {
if (mFinishedLoaders.contains(loaderId)) {
diff --git a/src/com/android/contacts/list/ContactListFilterLoader.java b/src/com/android/contacts/list/ContactListFilterLoader.java
index 6bca4ad..07c11bc 100644
--- a/src/com/android/contacts/list/ContactListFilterLoader.java
+++ b/src/com/android/contacts/list/ContactListFilterLoader.java
@@ -56,7 +56,7 @@
public static final int SOURCE_ID = 5;
public static final int GROUP_IS_READ_ONLY = 6;
- private static final String SELECTION =
+ public static final String SELECTION =
Groups.DELETED + "=0" +
" AND " + Groups.FAVORITES + "=0" +
" AND " + Groups.ACCOUNT_TYPE + " NOT NULL" +
diff --git a/src/com/android/contacts/test/InjectedServices.java b/src/com/android/contacts/test/InjectedServices.java
index b74481c..49b88be 100644
--- a/src/com/android/contacts/test/InjectedServices.java
+++ b/src/com/android/contacts/test/InjectedServices.java
@@ -17,6 +17,7 @@
package com.android.contacts.test;
import com.google.android.collect.Maps;
+import com.google.common.annotations.VisibleForTesting;
import android.content.ContentResolver;
import android.content.SharedPreferences;
@@ -34,6 +35,7 @@
private SharedPreferences mSharedPreferences;
private HashMap<String, Object> mSystemServices;
+ @VisibleForTesting
public void setContentResolver(ContentResolver contentResolver) {
this.mContentResolver = contentResolver;
}
@@ -42,6 +44,7 @@
return mContentResolver;
}
+ @VisibleForTesting
public void setSharedPreferences(SharedPreferences sharedPreferences) {
this.mSharedPreferences = sharedPreferences;
}
@@ -50,6 +53,7 @@
return mSharedPreferences;
}
+ @VisibleForTesting
public void setSystemService(String name, Object service) {
if (mSystemServices == null) {
mSystemServices = Maps.newHashMap();
diff --git a/src/com/android/contacts/widget/CompositeListAdapter.java b/src/com/android/contacts/widget/CompositeListAdapter.java
index bd0c8d6..692e073 100644
--- a/src/com/android/contacts/widget/CompositeListAdapter.java
+++ b/src/com/android/contacts/widget/CompositeListAdapter.java
@@ -15,6 +15,8 @@
*/
package com.android.contacts.widget;
+import com.google.common.annotations.VisibleForTesting;
+
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
@@ -64,7 +66,8 @@
mViewTypeCounts = new int[INITIAL_CAPACITY];
}
- public void addAdapter(ListAdapter adapter) {
+ @VisibleForTesting
+ /*package*/ void addAdapter(ListAdapter adapter) {
if (mSize >= mAdapters.length) {
int newCapacity = mSize + 2;
ListAdapter[] newAdapters = new ListAdapter[newCapacity];