1 /* 2 * Copyright (C) 2012 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 17 package com.android.contacts.common.util; 18 19 import static android.provider.ContactsContract.CommonDataKinds.Phone; 20 21 import android.test.AndroidTestCase; 22 import android.test.suitebuilder.annotation.SmallTest; 23 24 import com.android.contacts.common.R; 25 26 /** 27 * Unit tests for (@link ContactDisplayUtils} 28 */ 29 @SmallTest 30 public class ContactDisplayUtilTests extends AndroidTestCase { 31 32 public void testIsCustomPhoneTypeReturnsTrue() { 33 assertTrue(ContactDisplayUtils.isCustomPhoneType(Phone.TYPE_CUSTOM)); 34 assertTrue(ContactDisplayUtils.isCustomPhoneType(Phone.TYPE_ASSISTANT)); 35 } 36 37 public void testIsCustomPhoneTypeReturnsFalse() { 38 assertFalse(ContactDisplayUtils.isCustomPhoneType(Phone.TYPE_HOME)); 39 assertFalse(ContactDisplayUtils.isCustomPhoneType(Phone.TYPE_FAX_WORK)); 40 assertFalse(ContactDisplayUtils.isCustomPhoneType(Phone.TYPE_MOBILE)); 41 assertFalse(ContactDisplayUtils.isCustomPhoneType(Phone.TYPE_OTHER)); 42 } 43 44 public void testGetLabelForCallOrSmsReturnsCustomLabel() { 45 final CharSequence smsResult = ContactDisplayUtils.getLabelForCallOrSms(Phone.TYPE_CUSTOM, 46 "expected sms label", ContactDisplayUtils.INTERACTION_SMS, getContext()); 47 assertEquals("expected sms label", smsResult); 48 49 final CharSequence callResult = ContactDisplayUtils.getLabelForCallOrSms(Phone.TYPE_CUSTOM, 50 "expected call label", ContactDisplayUtils.INTERACTION_CALL, getContext()); 51 assertEquals("expected call label", callResult); 52 } 53 54 public void testGetLabelForCallOrSmsReturnsCallLabels() { 55 CharSequence result = ContactDisplayUtils.getLabelForCallOrSms(Phone.TYPE_HOME, "", 56 ContactDisplayUtils.INTERACTION_CALL, getContext()); 57 CharSequence expected = getContext().getResources().getText(R.string.call_home); 58 assertEquals(expected, result); 59 60 result = ContactDisplayUtils.getLabelForCallOrSms(Phone.TYPE_MOBILE, "", 61 ContactDisplayUtils.INTERACTION_CALL, getContext()); 62 expected = getContext().getResources().getText(R.string.call_mobile); 63 assertEquals(expected, result); 64 } 65 66 public void testGetLabelForCallOrSmsReturnsSmsLabels() { 67 CharSequence result = ContactDisplayUtils.getLabelForCallOrSms(Phone.TYPE_HOME, "", 68 ContactDisplayUtils.INTERACTION_SMS, getContext()); 69 CharSequence expected = getContext().getResources().getText(R.string.sms_home); 70 assertEquals(expected, result); 71 72 result = ContactDisplayUtils.getLabelForCallOrSms(Phone.TYPE_MOBILE, "", 73 ContactDisplayUtils.INTERACTION_SMS, getContext()); 74 expected = getContext().getResources().getText(R.string.sms_mobile); 75 assertEquals(expected, result); 76 } 77 78 public void testGetPhoneLabelResourceIdReturnsOther() { 79 assertEquals(R.string.call_other, ContactDisplayUtils.getPhoneLabelResourceId(null)); 80 } 81 82 public void testGetPhoneLabelResourceIdReturnsMatchHome() { 83 assertEquals(R.string.call_home, ContactDisplayUtils.getPhoneLabelResourceId( 84 Phone.TYPE_HOME)); 85 } 86 87 public void testGetSmsLabelResourceIdReturnsOther() { 88 assertEquals(R.string.sms_other, ContactDisplayUtils.getSmsLabelResourceId(null)); 89 } 90 91 public void testGetSmsLabelResourceIdReturnsMatchHome() { 92 assertEquals(R.string.sms_home, ContactDisplayUtils.getSmsLabelResourceId(Phone.TYPE_HOME)); 93 } 94 95 } 96