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 */ 16package com.android.internal.telephony.imsphone; 17 18import android.os.HandlerThread; 19import android.test.suitebuilder.annotation.SmallTest; 20import com.android.internal.telephony.PhoneNotifier; 21import com.android.internal.telephony.TelephonyTest; 22 23import org.junit.After; 24import org.junit.Before; 25import org.junit.Test; 26import org.mockito.Mock; 27import static org.junit.Assert.assertNotNull; 28import static org.junit.Assert.assertEquals; 29import static org.mockito.Mockito.eq; 30import static org.mockito.Mockito.times; 31import static org.mockito.Mockito.verify; 32 33public class ImsPhoneFactoryTest extends TelephonyTest { 34 35 @Mock 36 private PhoneNotifier mPhoneNotifer; 37 private ImsPhone mImsPhoneUT; 38 private ImsPhoneFactoryHandler mImsPhoneFactoryHandler; 39 40 private class ImsPhoneFactoryHandler extends HandlerThread { 41 42 private ImsPhoneFactoryHandler(String name) { 43 super(name); 44 } 45 @Override 46 public void onLooperPrepared() { 47 mImsPhoneUT = ImsPhoneFactory.makePhone(mContext, mPhoneNotifer, mPhone); 48 setReady(true); 49 } 50 } 51 52 @Before 53 public void setUp() throws Exception { 54 super.setUp(this.getClass().getSimpleName()); 55 mImsPhoneFactoryHandler = new ImsPhoneFactoryHandler(this.getClass().getSimpleName()); 56 mImsPhoneFactoryHandler.start(); 57 58 waitUntilReady(); 59 } 60 61 @After 62 public void tearDown() throws Exception { 63 mImsPhoneFactoryHandler.quit(); 64 super.tearDown(); 65 } 66 67 @Test @SmallTest 68 public void testMakeImsPhone() throws Exception { 69 assertNotNull(mImsPhoneUT); 70 assertEquals(mPhone, mImsPhoneUT.getDefaultPhone()); 71 72 mImsPhoneUT.notifyDataActivity(); 73 verify(mPhoneNotifer, times(1)).notifyDataActivity(eq(mImsPhoneUT)); 74 } 75} 76