Remove old @Postsubmit annotation
[android/platform/frameworks/opt/telephony.git] / tests / telephonytests / src / com / android / internal / telephony / imsphone / ImsExternalCallTrackerTest.java
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.internal.telephony.imsphone;
18
19 import com.android.ims.ImsCallProfile;
20 import com.android.ims.ImsExternalCallState;
21 import com.android.internal.telephony.Call;
22 import com.android.internal.telephony.Connection;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.ArgumentCaptor;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.mockito.MockitoAnnotations;
30 import org.mockito.invocation.InvocationOnMock;
31 import org.mockito.stubbing.Answer;
32
33 import android.net.Uri;
34 import android.support.test.filters.FlakyTest;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.Iterator;
39 import java.util.List;
40 import java.util.ListIterator;
41
42 import static org.junit.Assert.assertEquals;
43 import static org.junit.Assert.assertNull;
44 import static org.mockito.Matchers.any;
45 import static org.mockito.Mockito.doAnswer;
46 import static org.mockito.Mockito.mock;
47 import static org.mockito.Mockito.verify;
48 import static org.mockito.Mockito.when;
49
50 /**
51  * Unit tests for the {@link ImsExternalCallTracker}.
52  */
53 public class ImsExternalCallTrackerTest {
54     private static final Uri TEST_ADDRESS = Uri.parse("tel:6505551212");
55     private static final int CALL_ID = 1;
56
57     ImsExternalCallTracker mTracker;
58     @Mock
59     ImsPhone mImsPhone;
60     @Mock
61     ImsPullCall mImsPullCall;
62     @Mock
63     ImsExternalCallTracker.ImsCallNotify mCallNotifier;
64
65     @Before
66     public void setUp() throws Exception {
67         MockitoAnnotations.initMocks(this);
68
69         mTracker = new ImsExternalCallTracker(mImsPhone, mImsPullCall, mCallNotifier);
70     }
71
72     @FlakyTest
73     @Test
74     public void testAddExternalCall() {
75         List<ImsExternalCallState> dep = new ArrayList<>();
76         dep.add(
77                 new ImsExternalCallState(CALL_ID,
78                         TEST_ADDRESS,
79                         false /* isPullable */,
80                         ImsExternalCallState.CALL_STATE_CONFIRMED,
81                         ImsCallProfile.CALL_TYPE_VOICE,
82                         false /* isHeld */));
83
84         mTracker.refreshExternalCallState(dep);
85
86         ArgumentCaptor<Connection> connectionArgumentCaptor = ArgumentCaptor.forClass(
87                 Connection.class);
88         verify(mCallNotifier).notifyUnknownConnection(connectionArgumentCaptor.capture());
89
90
91         Connection connection = connectionArgumentCaptor.getValue();
92         assert(connection instanceof ImsExternalConnection);
93     }
94
95     @FlakyTest
96     @Test
97     public void testRemoveExternalCall() {
98         testAddExternalCall();
99
100         ImsExternalConnection connection = (ImsExternalConnection)
101                 mTracker.getConnectionById(CALL_ID);
102
103         List<ImsExternalCallState> dep = new ArrayList<>();
104         mTracker.refreshExternalCallState(dep);
105         verify(mCallNotifier).notifyPreciseCallStateChanged();
106         assertEquals(connection.getState(), Call.State.DISCONNECTED);
107         assertNull(mTracker.getConnectionById(CALL_ID));
108     }
109 }