CallLogListItemHelperTest.java revision a113689156ac38177fb8fdf82e5327c3f916d331
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.contacts.calllog; 18 19import com.android.contacts.PhoneCallDetails; 20import com.android.contacts.PhoneCallDetailsHelper; 21import com.android.contacts.PhoneCallDetailsViews; 22import com.android.contacts.R; 23import com.android.internal.telephony.CallerInfo; 24import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; 25 26import android.content.Context; 27import android.content.res.Resources; 28import android.provider.CallLog.Calls; 29import android.test.AndroidTestCase; 30import android.view.View; 31import android.widget.ImageView; 32import android.widget.LinearLayout; 33import android.widget.QuickContactBadge; 34import android.widget.TextView; 35 36/** 37 * Unit tests for {@link CallLogListItemHelper}. 38 */ 39public class CallLogListItemHelperTest extends AndroidTestCase { 40 /** A test phone number for phone calls. */ 41 private static final String TEST_NUMBER = "14125555555"; 42 /** The formatted version of {@link #TEST_NUMBER}. */ 43 private static final String TEST_FORMATTED_NUMBER = "1-412-255-5555"; 44 /** A test date value for phone calls. */ 45 private static final long TEST_DATE = 1300000000; 46 /** A test duration value for phone calls. */ 47 private static final long TEST_DURATION = 62300; 48 /** A test voicemail number. */ 49 private static final String TEST_VOICEMAIL_NUMBER = "123"; 50 /** The country ISO name used in the tests. */ 51 private static final String TEST_COUNTRY_ISO = "US"; 52 53 /** The object under test. */ 54 private CallLogListItemHelper mHelper; 55 56 /** The views used in the tests. */ 57 private CallLogListItemViews mViews; 58 private PhoneNumberHelper mPhoneNumberHelper; 59 60 @Override 61 protected void setUp() throws Exception { 62 super.setUp(); 63 Context context = getContext(); 64 Resources resources = context.getResources(); 65 CallTypeHelper callTypeHelper = new CallTypeHelper(resources, 66 resources.getDrawable(R.drawable.ic_call_incoming_holo_dark), 67 resources.getDrawable(R.drawable.ic_call_outgoing_holo_dark), 68 resources.getDrawable(R.drawable.ic_call_missed_holo_dark), 69 resources.getDrawable(R.drawable.ic_call_voicemail_holo_dark)); 70 mPhoneNumberHelper = new PhoneNumberHelper(resources, TEST_VOICEMAIL_NUMBER); 71 PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(context, 72 resources, callTypeHelper, mPhoneNumberHelper); 73 mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, mPhoneNumberHelper); 74 mViews = CallLogListItemViews.createForTest(new QuickContactBadge(context), 75 new ImageView(context), new ImageView(context), 76 PhoneCallDetailsViews.createForTest(new TextView(context), 77 new LinearLayout(context), new TextView(context), new TextView(context), 78 new TextView(context), new TextView(context)), 79 new View(context), new View(context), new TextView(context)); 80 } 81 82 @Override 83 protected void tearDown() throws Exception { 84 mHelper = null; 85 mViews = null; 86 super.tearDown(); 87 } 88 89 public void testSetPhoneCallDetails() { 90 setPhoneCallDetailsWithNumber("12125551234", "1-212-555-1234"); 91 assertEquals(View.VISIBLE, mViews.callView.getVisibility()); 92 assertEquals(View.GONE, mViews.playView.getVisibility()); 93 } 94 95 public void testSetPhoneCallDetails_Unknown() { 96 setPhoneCallDetailsWithNumber(CallerInfo.UNKNOWN_NUMBER, CallerInfo.UNKNOWN_NUMBER); 97 assertEquals(View.INVISIBLE, mViews.callView.getVisibility()); 98 assertEquals(View.GONE, mViews.playView.getVisibility()); 99 } 100 101 public void testSetPhoneCallDetails_Private() { 102 setPhoneCallDetailsWithNumber(CallerInfo.PRIVATE_NUMBER, CallerInfo.PRIVATE_NUMBER); 103 assertEquals(View.INVISIBLE, mViews.callView.getVisibility()); 104 assertEquals(View.GONE, mViews.playView.getVisibility()); 105 } 106 107 public void testSetPhoneCallDetails_Payphone() { 108 setPhoneCallDetailsWithNumber(CallerInfo.PAYPHONE_NUMBER, CallerInfo.PAYPHONE_NUMBER); 109 assertEquals(View.INVISIBLE, mViews.callView.getVisibility()); 110 assertEquals(View.GONE, mViews.playView.getVisibility()); 111 } 112 113 public void testSetPhoneCallDetails_VoicemailNumber() { 114 setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER, TEST_VOICEMAIL_NUMBER); 115 assertEquals(View.VISIBLE, mViews.callView.getVisibility()); 116 assertEquals(View.GONE, mViews.playView.getVisibility()); 117 } 118 119 public void testSetPhoneCallDetails_Voicemail() { 120 setPhoneCallDetailsWithTypes(Calls.VOICEMAIL_TYPE); 121 assertEquals(View.VISIBLE, mViews.callView.getVisibility()); 122 assertEquals(View.VISIBLE, mViews.playView.getVisibility()); 123 } 124 125 /** Sets the details of a phone call using the specified phone number. */ 126 private void setPhoneCallDetailsWithNumber(String number, String formattedNumber) { 127 PhoneNumber structuredPhoneNumber = 128 mPhoneNumberHelper.parsePhoneNumber(number, TEST_COUNTRY_ISO); 129 mHelper.setPhoneCallDetails(mViews, 130 new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber, 131 new int[]{ Calls.INCOMING_TYPE }, TEST_DATE, TEST_DURATION), 132 true, false); 133 } 134 135 /** Sets the details of a phone call using the specified call type. */ 136 private void setPhoneCallDetailsWithTypes(int... types) { 137 PhoneNumber structuredPhoneNumber = 138 mPhoneNumberHelper.parsePhoneNumber(TEST_NUMBER, TEST_COUNTRY_ISO); 139 mHelper.setPhoneCallDetails(mViews, 140 new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, structuredPhoneNumber, 141 types, TEST_DATE, TEST_DURATION), 142 true, false); 143 } 144} 145