1 /*
2  * Copyright (C) 2022 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.server.telecom.tests;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNull;
21 
22 import android.content.ComponentName;
23 import android.net.Uri;
24 import android.telecom.CallerInfo;
25 import android.telecom.PhoneAccountHandle;
26 
27 import androidx.test.filters.SmallTest;
28 
29 import com.android.server.telecom.MissedCallNotifier;
30 
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.JUnit4;
36 
37 @RunWith(JUnit4.class)
38 public class MissedCallNotifierTest extends TelecomTestCase {
39     private static final ComponentName COMPONENT_NAME =
40             new ComponentName("com.anything", "com.whatever");
41     private static final Uri TEL_CALL_HANDLE = Uri.parse("tel:+11915552620");
42     private static final long CALL_TIMESTAMP = 1;
43 
44     @Override
45     @Before
setUp()46     public void setUp() throws Exception {
47         super.setUp();
48     }
49 
50     @Override
51     @After
tearDown()52     public void tearDown() throws Exception {
53         super.tearDown();
54     }
55 
56     @SmallTest
57     @Test
testCallInfoFactory()58     public void testCallInfoFactory() {
59         final CallerInfo callerInfo = new CallerInfo();
60         final String phoneNumber = "1111";
61         final String name = "name";
62         callerInfo.setPhoneNumber(phoneNumber);
63         callerInfo.setName(name);
64         final PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(COMPONENT_NAME, "id");
65 
66         MissedCallNotifier.CallInfo callInfo = new MissedCallNotifier.CallInfoFactory()
67                 .makeCallInfo(callerInfo, phoneAccountHandle, TEL_CALL_HANDLE, CALL_TIMESTAMP);
68 
69         assertEquals(callerInfo, callInfo.getCallerInfo());
70         assertEquals(phoneAccountHandle, callInfo.getPhoneAccountHandle());
71         assertEquals(TEL_CALL_HANDLE, callInfo.getHandle());
72         assertEquals(TEL_CALL_HANDLE.getSchemeSpecificPart(),
73                 callInfo.getHandleSchemeSpecificPart());
74         assertEquals(CALL_TIMESTAMP, callInfo.getCreationTimeMillis());
75         assertEquals(phoneNumber, callInfo.getPhoneNumber());
76         assertEquals(name, callInfo.getName());
77     }
78 
79     @SmallTest
80     @Test
testCallInfoFactoryNullParam()81     public void testCallInfoFactoryNullParam() {
82         MissedCallNotifier.CallInfo callInfo = new MissedCallNotifier.CallInfoFactory()
83                 .makeCallInfo(null, null, null, CALL_TIMESTAMP);
84 
85         assertNull(callInfo.getCallerInfo());
86         assertNull(callInfo.getPhoneAccountHandle());
87         assertNull(callInfo.getHandle());
88         assertNull(callInfo.getHandleSchemeSpecificPart());
89         assertEquals(CALL_TIMESTAMP, callInfo.getCreationTimeMillis());
90         assertNull(callInfo.getPhoneNumber());
91         assertNull(callInfo.getName());
92     }
93 }
94