19cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell/*
29cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * Copyright (C) 2016 The Android Open Source Project
39cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell *
49cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * Licensed under the Apache License, Version 2.0 (the "License");
59cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * you may not use this file except in compliance with the License.
69cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * You may obtain a copy of the License at
79cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell *
89cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell *      http://www.apache.org/licenses/LICENSE-2.0
99cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell *
109cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * Unless required by applicable law or agreed to in writing, software
119cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * distributed under the License is distributed on an "AS IS" BASIS,
129cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * See the License for the specific language governing permissions and
149cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell * limitations under the License
159cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell */
169cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
179cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellpackage com.android.incallui;
189cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
199cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellimport android.test.AndroidTestCase;
209cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellimport android.test.suitebuilder.annotation.MediumTest;
219cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
229cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellimport com.android.contacts.common.preference.ContactsPreferences;
239cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellimport com.android.incallui.ContactInfoCache.ContactCacheEntry;
249cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
259cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellimport org.mockito.Mock;
269cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellimport org.mockito.Mockito;
279cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellimport org.mockito.MockitoAnnotations;
289cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
299cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell@MediumTest
309cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwellpublic class CallCardPresenterTest extends AndroidTestCase {
319cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
329cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    private static final String NAME_PRIMARY = "Full Name";
339cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    private static final String NAME_ALTERNATIVE = "Name, Full";
349cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    private static final String LOCATION = "US";
359cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    private static final String NUMBER = "8006459001";
369cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
379cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    @Mock private ContactsPreferences mContactsPreferences;
389cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    private ContactCacheEntry mUnlockedContactInfo;
399cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    private ContactCacheEntry mLockedContactInfo;
409cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
419cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    @Override
429cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void setUp() throws Exception {
439cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        super.setUp();
449cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        MockitoAnnotations.initMocks(this);
459cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
469cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        Mockito.when(mContactsPreferences.getDisplayOrder())
479cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell                .thenReturn(ContactsPreferences.DISPLAY_ORDER_PRIMARY);
489cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
499cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        // Unlocked all contact info is available
509cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mUnlockedContactInfo = new ContactCacheEntry();
519cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mUnlockedContactInfo.namePrimary = NAME_PRIMARY;
529cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mUnlockedContactInfo.nameAlternative = NAME_ALTERNATIVE;
539cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mUnlockedContactInfo.location = LOCATION;
549cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mUnlockedContactInfo.number = NUMBER;
559cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
569cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        // Locked only number and location are available
579cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mLockedContactInfo = new ContactCacheEntry();
589cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mLockedContactInfo .location = LOCATION;
599cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        mLockedContactInfo .number = NUMBER;
609cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
619cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
629cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    @Override
639cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void tearDown() throws Exception {
649cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        super.tearDown();
659cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactsPreferencesFactory.setTestInstance(null);
669cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
679cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
689cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void testGetNameForCall_Unlocked() {
699cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactsPreferencesFactory.setTestInstance(mContactsPreferences);
709cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        CallCardPresenter presenter = new CallCardPresenter();
719cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        presenter.init(getContext(), null);
729cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
739cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        assertEquals(NAME_PRIMARY, presenter.getNameForCall(mUnlockedContactInfo));
749cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
759cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
769cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void testGetNameForCall_Locked() {
779cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactsPreferencesFactory.setTestInstance(null);
789cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        CallCardPresenter presenter = new CallCardPresenter();
799cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        presenter.init(getContext(), null);
809cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
819cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        assertEquals(NUMBER, presenter.getNameForCall(mLockedContactInfo));
829cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
839cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
849cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void testGetNameForCall_EmptyPreferredName() {
859cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactCacheEntry contactInfo = new ContactCacheEntry();
869cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        contactInfo.number = NUMBER;
879cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
889cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactsPreferencesFactory.setTestInstance(null);
899cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        CallCardPresenter presenter = new CallCardPresenter();
909cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        presenter.init(getContext(), null);
919cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
929cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        assertEquals(NUMBER, presenter.getNameForCall(contactInfo));
939cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
949cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
959cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void testGetNumberForCall_Unlocked() {
969cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactsPreferencesFactory.setTestInstance(mContactsPreferences);
979cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        CallCardPresenter presenter = new CallCardPresenter();
989cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        presenter.init(getContext(), null);
999cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
1009cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        assertEquals(NUMBER, presenter.getNumberForCall(mUnlockedContactInfo));
1019cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
1029cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
1039cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void testGetNumberForCall_Locked() {
1049cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactsPreferencesFactory.setTestInstance(null);
1059cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        CallCardPresenter presenter = new CallCardPresenter();
1069cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        presenter.init(getContext(), null);
1079cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
1089cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        assertEquals(LOCATION, presenter.getNumberForCall(mLockedContactInfo));
1099cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
1109cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
1119cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    public void testGetNumberForCall_EmptyPreferredName() {
1129cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactCacheEntry contactInfo = new ContactCacheEntry();
1139cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        contactInfo.location = LOCATION;
1149cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
1159cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        ContactsPreferencesFactory.setTestInstance(null);
1169cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        CallCardPresenter presenter = new CallCardPresenter();
1179cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        presenter.init(getContext(), null);
1189cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell
1199cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell        assertEquals(LOCATION, presenter.getNumberForCall(contactInfo));
1209cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell    }
1219cd03e1e3c319f7633638615074da3028eb45c2bBrandon Maxwell}
122