From 74479d448bc39c3534585a627fba603aa89e93ca Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 2 Apr 2015 17:23:33 -0700 Subject: Create ContactInfoCache from CallLogAdapter. This pulls code from the CallLogAdapter, with only tweaks to variable names and comments, to create a ContactInfoCache responsible for logic pertaining to looking up and caching contact info. The logic is intended to be unchanged for now, although in the future it can/should probably be cleaned up sometime. Bug: 20038300 Change-Id: I60a57b0a665496522a6b51c9e6e41a4fd6dbad1f --- .../android/dialer/calllog/CallLogAdapterTest.java | 41 ++++++++++++++-------- .../dialer/calllog/CallLogFragmentTest.java | 2 +- 2 files changed, 28 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java index 0f175117d..dbdde6875 100644 --- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java @@ -23,6 +23,8 @@ import android.test.suitebuilder.annotation.SmallTest; import android.view.View; import android.widget.LinearLayout; +import com.android.dialer.contactinfo.ContactInfoCache; +import com.android.dialer.contactinfo.ContactInfoCache.OnContactInfoChangedListener; import com.google.common.collect.Lists; import java.util.List; @@ -88,9 +90,9 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.bindStandAloneView(mView, getContext(), mCursor); // There is one request for contact details. - assertEquals(1, mAdapter.requests.size()); + assertEquals(1, mAdapter.getContactInfoCache().requests.size()); - TestCallLogAdapter.Request request = mAdapter.requests.get(0); + TestContactInfoCache.Request request = mAdapter.getContactInfoCache().requests.get(0); // It is for the number we need to show. assertEquals(TEST_NUMBER, request.number); // It has the right country. @@ -106,9 +108,9 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.bindStandAloneView(mView, getContext(), mCursor); // There is one request for contact details. - assertEquals(1, mAdapter.requests.size()); + assertEquals(1, mAdapter.getContactInfoCache().requests.size()); - TestCallLogAdapter.Request request = mAdapter.requests.get(0); + TestContactInfoCache.Request request = mAdapter.getContactInfoCache().requests.get(0); // The values passed to the request, match the ones in the call log cache. assertEquals(TEST_NAME, request.callLogInfo.name); assertEquals(1, request.callLogInfo.type); @@ -124,9 +126,9 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.bindStandAloneView(mView, getContext(), mCursor); // There is one request for contact details. - assertEquals(1, mAdapter.requests.size()); + assertEquals(1, mAdapter.getContactInfoCache().requests.size()); - TestCallLogAdapter.Request request = mAdapter.requests.get(0); + TestContactInfoCache.Request request = mAdapter.getContactInfoCache().requests.get(0); // Since there is something in the cache, it is not an immediate request. assertFalse("should not be immediate", request.immediate); } @@ -139,7 +141,7 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.bindStandAloneView(mView, getContext(), mCursor); // Cache and call log are up-to-date: no need to request update. - assertEquals(0, mAdapter.requests.size()); + assertEquals(0, mAdapter.getContactInfoCache().requests.size()); } public void testBindView_MismatchBetwenCallLogAndMemoryCache_EnqueueRequest() { @@ -154,9 +156,9 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.bindStandAloneView(mView, getContext(), mCursor); // There is one request for contact details. - assertEquals(1, mAdapter.requests.size()); + assertEquals(1, mAdapter.getContactInfoCache().requests.size()); - TestCallLogAdapter.Request request = mAdapter.requests.get(0); + TestContactInfoCache.Request request = mAdapter.getContactInfoCache().requests.get(0); // Since there is something in the cache, it is not an immediate request. assertFalse("should not be immediate", request.immediate); } @@ -191,9 +193,20 @@ public class CallLogAdapterTest extends AndroidTestCase { /** * Subclass of {@link CallLogAdapter} used in tests to intercept certain calls. */ - // TODO: This would be better done by splitting the contact lookup into a collaborator class - // instead. private static final class TestCallLogAdapter extends CallLogAdapter { + public TestCallLogAdapter(Context context, CallFetcher callFetcher, + ContactInfoHelper contactInfoHelper) { + super(context, callFetcher, contactInfoHelper, null, null); + mContactInfoCache = new TestContactInfoCache( + contactInfoHelper, mOnContactInfoChangedListener); + } + + public TestContactInfoCache getContactInfoCache() { + return (TestContactInfoCache) mContactInfoCache; + } + } + + private static final class TestContactInfoCache extends ContactInfoCache { public static class Request { public final String number; public final String countryIso; @@ -211,9 +224,9 @@ public class CallLogAdapterTest extends AndroidTestCase { public final List requests = Lists.newArrayList(); - public TestCallLogAdapter(Context context, CallFetcher callFetcher, - ContactInfoHelper contactInfoHelper) { - super(context, callFetcher, contactInfoHelper, null, null); + public TestContactInfoCache( + ContactInfoHelper contactInfoHelper, OnContactInfoChangedListener listener) { + super(contactInfoHelper, listener); } @Override diff --git a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java index 5d9a05f83..055342250 100644 --- a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java @@ -126,7 +126,7 @@ public class CallLogFragmentTest extends ActivityInstrumentationTestCase2