1 /* 2 * Copyright (C) 2016 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.incallui; 18 19 import android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.MediumTest; 21 22 import com.android.contacts.common.preference.ContactsPreferences; 23 import com.android.incallui.ContactInfoCache.ContactCacheEntry; 24 25 import org.mockito.Mock; 26 import org.mockito.Mockito; 27 import org.mockito.MockitoAnnotations; 28 29 @MediumTest 30 public class StatusBarNotifierTest extends AndroidTestCase { 31 32 private static final String NAME_PRIMARY = "Full Name"; 33 private static final String NAME_ALTERNATIVE = "Name, Full"; 34 private static final String LOCATION = "US"; 35 private static final String NUMBER = "8006459001"; 36 37 @Mock private Call mCall; 38 @Mock private ContactsPreferences mContactsPreferences; 39 private ContactCacheEntry mUnlockedContactInfo; 40 private ContactCacheEntry mLockedContactInfo; 41 42 @Override setUp()43 public void setUp() throws Exception { 44 super.setUp(); 45 MockitoAnnotations.initMocks(this); 46 47 Mockito.when(mContactsPreferences.getDisplayOrder()) 48 .thenReturn(ContactsPreferences.DISPLAY_ORDER_PRIMARY); 49 50 // Unlocked all contact info is available 51 mUnlockedContactInfo = new ContactCacheEntry(); 52 mUnlockedContactInfo.namePrimary = NAME_PRIMARY; 53 mUnlockedContactInfo.nameAlternative = NAME_ALTERNATIVE; 54 mUnlockedContactInfo.location = LOCATION; 55 mUnlockedContactInfo.number = NUMBER; 56 57 // Locked only number and location are available 58 mLockedContactInfo = new ContactCacheEntry(); 59 mLockedContactInfo .location = LOCATION; 60 mLockedContactInfo .number = NUMBER; 61 } 62 63 @Override tearDown()64 public void tearDown() throws Exception { 65 super.tearDown(); 66 ContactsPreferencesFactory.setTestInstance(null); 67 } 68 testGetContentTitle_ConferenceCall()69 public void testGetContentTitle_ConferenceCall() { 70 ContactsPreferencesFactory.setTestInstance(null); 71 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null); 72 73 Mockito.when(mCall.isConferenceCall()).thenReturn(true); 74 Mockito.when(mCall.hasProperty(Mockito.anyInt())).thenReturn(false); 75 76 assertEquals(mContext.getResources().getString(R.string.card_title_conf_call), 77 statusBarNotifier.getContentTitle(null, mCall)); 78 } 79 testGetContentTitle_Unlocked()80 public void testGetContentTitle_Unlocked() { 81 ContactsPreferencesFactory.setTestInstance(mContactsPreferences); 82 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null); 83 assertEquals(NAME_PRIMARY, statusBarNotifier.getContentTitle(mUnlockedContactInfo, mCall)); 84 } 85 testGetContentTitle_Locked()86 public void testGetContentTitle_Locked() { 87 ContactsPreferencesFactory.setTestInstance(null); 88 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null); 89 assertEquals(NUMBER, statusBarNotifier.getContentTitle(mLockedContactInfo, mCall)); 90 } 91 testGetContentTitle_EmptyPreferredName()92 public void testGetContentTitle_EmptyPreferredName() { 93 ContactCacheEntry contactCacheEntry = new ContactCacheEntry(); 94 contactCacheEntry.number = NUMBER; 95 StatusBarNotifier statusBarNotifier = new StatusBarNotifier(mContext, null); 96 assertEquals(NUMBER, statusBarNotifier.getContentTitle(contactCacheEntry, mCall)); 97 } 98 } 99