From a26fd83cf27789b3e40ac680d7be75ed984abb39 Mon Sep 17 00:00:00 2001 From: Nancy Chen Date: Thu, 22 Oct 2015 17:02:01 -0700 Subject: Add the city/locality to the displayed business information. To disambiguate, include the city/locality with the address in the form "[street address], [city/locality]" in the contact interactions. Also add tests to ensure the construction of the location info is correct. Bug: 23351559 Change-Id: Ib0b2ce8a80a8494d5b006a6a74ad94447befc0ef --- .../incallui/InCallContactInteractionsTest.java | 68 ++++++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) (limited to 'InCallUI/tests') diff --git a/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java b/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java index c3ec08d69..b97be01ee 100644 --- a/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java +++ b/InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java @@ -16,15 +16,18 @@ package com.android.incallui; +import android.location.Address; import android.test.AndroidTestCase; import android.util.Pair; import com.android.incallui.InCallContactInteractions.BusinessContextInfo; import java.util.Calendar; +import java.util.Locale; public class InCallContactInteractionsTest extends AndroidTestCase { private InCallContactInteractions mInCallContactInteractions; + private static final float TEST_DISTANCE = (float) 1234.56; @Override protected void setUp() { @@ -35,7 +38,7 @@ public class InCallContactInteractionsTest extends AndroidTestCase { Calendar currentTimeForTest = Calendar.getInstance(); currentTimeForTest.set(Calendar.HOUR_OF_DAY, 10); BusinessContextInfo info = - mInCallContactInteractions.constructHoursInfoByTime( + mInCallContactInteractions.constructHoursInfo( currentTimeForTest, Pair.create("0800", "2000")); assertEquals(mContext.getString(R.string.open_now), info.heading); @@ -45,7 +48,7 @@ public class InCallContactInteractionsTest extends AndroidTestCase { Calendar currentTimeForTest = Calendar.getInstance(); currentTimeForTest.set(Calendar.HOUR_OF_DAY, 6); BusinessContextInfo info = - mInCallContactInteractions.constructHoursInfoByTime( + mInCallContactInteractions.constructHoursInfo( currentTimeForTest, Pair.create("0800", "2000")); assertEquals(mContext.getString(R.string.closed_now), info.heading); @@ -55,7 +58,7 @@ public class InCallContactInteractionsTest extends AndroidTestCase { Calendar currentTimeForTest = Calendar.getInstance(); currentTimeForTest.set(Calendar.HOUR_OF_DAY, 21); BusinessContextInfo info = - mInCallContactInteractions.constructHoursInfoByTime( + mInCallContactInteractions.constructHoursInfo( currentTimeForTest, Pair.create("0800", "2000")); assertEquals(mContext.getString(R.string.closed_now), info.heading); @@ -65,9 +68,66 @@ public class InCallContactInteractionsTest extends AndroidTestCase { Calendar currentTimeForTest = Calendar.getInstance(); currentTimeForTest.set(Calendar.HOUR_OF_DAY, 21); BusinessContextInfo info = - mInCallContactInteractions.constructHoursInfoByTime( + mInCallContactInteractions.constructHoursInfo( currentTimeForTest, Pair.create("", "2000")); assertEquals(null, info); } + + public void testLocationInfo_ForUS() { + BusinessContextInfo info = + mInCallContactInteractions.constructLocationInfo( + Locale.US, + getAddressForTest(), + TEST_DISTANCE); + assertEquals("0.8 mi away", info.heading); + assertEquals("Test address, Test locality", info.detail); + } + + public void testLocationInfo_ForNotUS() { + BusinessContextInfo info = + mInCallContactInteractions.constructLocationInfo( + Locale.CANADA, + getAddressForTest(), + TEST_DISTANCE); + assertEquals("1.2 km away", info.heading); + assertEquals("Test address, Test locality", info.detail); + } + + public void testLocationInfo_NoLocality() { + Address address = getAddressForTest(); + address.setLocality(null); + BusinessContextInfo info = + mInCallContactInteractions.constructLocationInfo( + Locale.CANADA, + address, + TEST_DISTANCE); + assertEquals("1.2 km away", info.heading); + assertEquals("Test address", info.detail); + } + + public void testLocationInfo_NoAddress() { + BusinessContextInfo info = + mInCallContactInteractions.constructLocationInfo( + Locale.CANADA, + null, + TEST_DISTANCE); + assertEquals(null, info); + } + + public void testLocationInfo_NoDistance() { + BusinessContextInfo info = + mInCallContactInteractions.constructLocationInfo( + Locale.US, + getAddressForTest(), + DistanceHelper.DISTANCE_NOT_FOUND); + assertEquals(null, info.heading); + } + + private Address getAddressForTest() { + Address address = new Address(Locale.US); + address.setAddressLine(0, "Test address"); + address.setLocality("Test locality"); + return address; + } } -- cgit v1.2.3