CdmaSmsDispatcherTest.java revision 6ba18ef5f3733709f16ef03b3d2b2de076b63c3e
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.internal.telephony.cdma; 18 19import android.os.HandlerThread; 20import android.os.Message; 21import android.test.suitebuilder.annotation.SmallTest; 22 23import com.android.internal.telephony.ImsSMSDispatcher; 24import com.android.internal.telephony.SMSDispatcher; 25import com.android.internal.telephony.TelephonyTest; 26 27import static org.mockito.Mockito.*; 28 29import org.junit.After; 30import org.junit.Before; 31import org.junit.Test; 32import org.mockito.Mock; 33 34public class CdmaSmsDispatcherTest extends TelephonyTest { 35 @Mock 36 private android.telephony.SmsMessage mSmsMessage; 37 @Mock 38 private SmsMessage mCdmaSmsMessage; 39 @Mock 40 private ImsSMSDispatcher mImsSmsDispatcher; 41 @Mock 42 private SMSDispatcher.SmsTracker mSmsTracker; 43 44 private CdmaSMSDispatcher mCdmaSmsDispatcher; 45 46 private class CdmaSmsDispatcherTestHandler extends HandlerThread { 47 48 private CdmaSmsDispatcherTestHandler(String name) { 49 super(name); 50 } 51 52 @Override 53 public void onLooperPrepared() { 54 mCdmaSmsDispatcher = new CdmaSMSDispatcher(mPhone, mSmsUsageMonitor, 55 mImsSmsDispatcher); 56 setReady(true); 57 } 58 } 59 60 @Before 61 public void setUp() throws Exception { 62 super.setUp(this.getClass().getSimpleName()); 63 64 setupMockPackagePermissionChecks(); 65 66 new CdmaSmsDispatcherTestHandler(TAG).start(); 67 waitUntilReady(); 68 } 69 70 @After 71 public void tearDown() throws Exception { 72 mCdmaSmsDispatcher = null; 73 super.tearDown(); 74 } 75 76 @Test @SmallTest 77 public void testSendSms() { 78 doReturn(mServiceState).when(mPhone).getServiceState(); 79 mCdmaSmsDispatcher.sendSms(mSmsTracker); 80 verify(mSimulatedCommandsVerifier).sendCdmaSms(any(byte[].class), any(Message.class)); 81 } 82 83 @Test @SmallTest 84 public void testSendText() { 85 mCdmaSmsDispatcher.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG, 86 null, null, null, null, false); 87 verify(mSimulatedCommandsVerifier).sendCdmaSms(any(byte[].class), any(Message.class)); 88 } 89 90 @Test @SmallTest 91 public void testSendTextWithOutDesAddr() { 92 mCdmaSmsDispatcher.sendText(null, "222" /*scAddr*/, TAG, 93 null, null, null, null, false); 94 verify(mSimulatedCommandsVerifier, times(0)).sendImsGsmSms(anyString(), anyString(), 95 anyInt(), anyInt(), any(Message.class)); 96 } 97} 98