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