CallLogListItemHelperTest.java revision e0b2f1e2d01d1ac52ba207dc7ce76971d853298e
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 android.content.Context;
20import android.content.res.Resources;
21import android.provider.CallLog.Calls;
22import android.test.AndroidTestCase;
23import android.view.View;
24
25import com.android.contacts.PhoneCallDetails;
26import com.android.contacts.PhoneCallDetailsHelper;
27import com.android.internal.telephony.CallerInfo;
28
29/**
30 * Unit tests for {@link CallLogListItemHelper}.
31 */
32public class CallLogListItemHelperTest extends AndroidTestCase {
33    /** A test phone number for phone calls. */
34    private static final String TEST_NUMBER = "14125555555";
35    /** The formatted version of {@link #TEST_NUMBER}. */
36    private static final String TEST_FORMATTED_NUMBER = "1-412-255-5555";
37    /** A test date value for phone calls. */
38    private static final long TEST_DATE = 1300000000;
39    /** A test duration value for phone calls. */
40    private static final long TEST_DURATION = 62300;
41    /** A test voicemail number. */
42    private static final String TEST_VOICEMAIL_NUMBER = "123";
43    /** The country ISO name used in the tests. */
44    private static final String TEST_COUNTRY_ISO = "US";
45    /** The geocoded location used in the tests. */
46    private static final String TEST_GEOCODE = "United States";
47
48    /** The object under test. */
49    private CallLogListItemHelper mHelper;
50
51    /** The views used in the tests. */
52    private CallLogListItemViews mViews;
53    private PhoneNumberHelper mPhoneNumberHelper;
54
55    @Override
56    protected void setUp() throws Exception {
57        super.setUp();
58        Context context = getContext();
59        Resources resources = context.getResources();
60        CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
61        mPhoneNumberHelper = new TestPhoneNumberHelper(resources, TEST_VOICEMAIL_NUMBER);
62        PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(
63                resources, callTypeHelper, mPhoneNumberHelper);
64        mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, mPhoneNumberHelper, resources);
65        mViews = CallLogListItemViews.createForTest(context);
66    }
67
68    @Override
69    protected void tearDown() throws Exception {
70        mHelper = null;
71        mViews = null;
72        super.tearDown();
73    }
74
75    public void testSetPhoneCallDetails() {
76        setPhoneCallDetailsWithNumber("12125551234", "1-212-555-1234");
77        assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility());
78    }
79
80    public void testSetPhoneCallDetails_Unknown() {
81        setPhoneCallDetailsWithNumber(CallerInfo.UNKNOWN_NUMBER, CallerInfo.UNKNOWN_NUMBER);
82        assertNoCallButton();
83    }
84
85    public void testSetPhoneCallDetails_Private() {
86        setPhoneCallDetailsWithNumber(CallerInfo.PRIVATE_NUMBER, CallerInfo.PRIVATE_NUMBER);
87        assertNoCallButton();
88    }
89
90    public void testSetPhoneCallDetails_Payphone() {
91        setPhoneCallDetailsWithNumber(CallerInfo.PAYPHONE_NUMBER, CallerInfo.PAYPHONE_NUMBER);
92        assertNoCallButton();
93    }
94
95    public void testSetPhoneCallDetails_VoicemailNumber() {
96        setPhoneCallDetailsWithNumber(TEST_VOICEMAIL_NUMBER, TEST_VOICEMAIL_NUMBER);
97        assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility());
98    }
99
100    public void testSetPhoneCallDetails_ReadVoicemail() {
101        setPhoneCallDetailsWithTypes(Calls.VOICEMAIL_TYPE);
102        assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility());
103    }
104
105    public void testSetPhoneCallDetails_UnreadVoicemail() {
106        setUnreadPhoneCallDetailsWithTypes(Calls.VOICEMAIL_TYPE);
107        assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility());
108    }
109
110    public void testSetPhoneCallDetails_VoicemailFromUnknown() {
111        setPhoneCallDetailsWithNumberAndType(CallerInfo.UNKNOWN_NUMBER, CallerInfo.UNKNOWN_NUMBER,
112                Calls.VOICEMAIL_TYPE);
113        assertEquals(View.VISIBLE, mViews.secondaryActionView.getVisibility());
114    }
115
116    /** Asserts that the whole call area is gone. */
117    private void assertNoCallButton() {
118        assertEquals(View.GONE, mViews.secondaryActionView.getVisibility());
119        assertEquals(View.GONE, mViews.dividerView.getVisibility());
120    }
121
122    /** Sets the details of a phone call using the specified phone number. */
123    private void setPhoneCallDetailsWithNumber(String number, String formattedNumber) {
124        setPhoneCallDetailsWithNumberAndType(number, formattedNumber, Calls.INCOMING_TYPE);
125    }
126
127    /** Sets the details of a phone call using the specified phone number. */
128    private void setPhoneCallDetailsWithNumberAndType(String number, String formattedNumber,
129            int callType) {
130        mHelper.setPhoneCallDetails(mViews,
131                new PhoneCallDetails(number, formattedNumber, TEST_COUNTRY_ISO, TEST_GEOCODE,
132                        new int[]{ callType }, TEST_DATE, TEST_DURATION),
133                false);
134    }
135
136    /** Sets the details of a phone call using the specified call type. */
137    private void setPhoneCallDetailsWithTypes(int... types) {
138        mHelper.setPhoneCallDetails(mViews,
139                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO,
140                        TEST_GEOCODE, types, TEST_DATE, TEST_DURATION),
141                false);
142    }
143
144    /** Sets the details of a phone call using the specified call type. */
145    private void setUnreadPhoneCallDetailsWithTypes(int... types) {
146        mHelper.setPhoneCallDetails(mViews,
147                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO,
148                        TEST_GEOCODE, types, TEST_DATE, TEST_DURATION),
149                true);
150    }
151}
152