diff options
Diffstat (limited to 'InCallUI/tests')
-rw-r--r-- | InCallUI/tests/src/com/android/incallui/InCallContactInteractionsTest.java | 68 |
1 files changed, 64 insertions, 4 deletions
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; + } } |