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
17package com.android.dialer.calllog;
18
19import android.content.ComponentName;
20import android.telecom.PhoneAccountHandle;
21import android.test.AndroidTestCase;
22import android.test.suitebuilder.annotation.SmallTest;
23
24public class PhoneAccountUtilsTest extends AndroidTestCase {
25
26    private static final String VALID_COMPONENT_NAME =
27            "com.android.dialer.calllog/com.android.dialer.calllog.PhoneAccountUtilsTest";
28    private static final String VALID_ACCOUNT_ID = "Account1";
29
30    @SmallTest
31    public void testGetAccount_CorrectParams() {
32        ComponentName correctComponentName =
33                ComponentName.unflattenFromString(VALID_COMPONENT_NAME);
34        PhoneAccountHandle correctPhoneAccountHandle = new PhoneAccountHandle(correctComponentName,
35                VALID_ACCOUNT_ID);
36
37        PhoneAccountHandle testPhoneAccountHandle =
38                PhoneAccountUtils.getAccount(VALID_COMPONENT_NAME, VALID_ACCOUNT_ID);
39
40        assertTrue(correctPhoneAccountHandle.equals(testPhoneAccountHandle));
41    }
42
43    @SmallTest
44    public void testGetAccount_ComponentStringNoClassName() {
45        final String malformedComponentName = "com.android.dialer.calllog/";
46
47        PhoneAccountHandle testPhoneAccountHandle =
48                PhoneAccountUtils.getAccount(malformedComponentName, VALID_ACCOUNT_ID);
49
50        assertNull(testPhoneAccountHandle);
51    }
52
53    @SmallTest
54    public void testGetAccount_ComponentStringInvalid() {
55        final String malformedComponentName = "com.android.dialer.calllog";
56
57        PhoneAccountHandle testPhoneAccountHandle =
58                PhoneAccountUtils.getAccount(malformedComponentName, VALID_ACCOUNT_ID);
59
60        assertNull(testPhoneAccountHandle);
61    }
62
63    @SmallTest
64    public void testGetAccount_NoComponentName() {
65        final String blankComponentName = "";
66
67        PhoneAccountHandle testPhoneAccountHandle =
68                PhoneAccountUtils.getAccount(blankComponentName, VALID_ACCOUNT_ID);
69
70        assertNull(testPhoneAccountHandle);
71    }
72
73    @SmallTest
74    public void testGetAccount_NoAccountId() {
75        final String blankAccountId = "";
76
77        PhoneAccountHandle testPhoneAccountHandle =
78                PhoneAccountUtils.getAccount(VALID_COMPONENT_NAME, blankAccountId);
79
80        assertNull(testPhoneAccountHandle);
81    }
82
83    @SmallTest
84    public void testGetAccount_NoAccountIdOrComponentName() {
85        final String blankComponentName = "";
86        final String blankAccountId = "";
87
88        PhoneAccountHandle testPhoneAccountHandle =
89                PhoneAccountUtils.getAccount(VALID_COMPONENT_NAME, blankAccountId);
90
91        assertNull(testPhoneAccountHandle);
92    }
93
94    @SmallTest
95    public void testGetAccount_NullAccountIdAndComponentName() {
96        final String blankComponentName = null;
97        final String blankAccountId = null;
98
99        PhoneAccountHandle testPhoneAccountHandle =
100                PhoneAccountUtils.getAccount(VALID_COMPONENT_NAME, blankAccountId);
101
102        assertNull(testPhoneAccountHandle);
103    }
104}
105