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.cellbroadcastreceiver; 18 19 import android.content.Context; 20 import android.os.PersistableBundle; 21 import android.util.Log; 22 import android.telephony.CarrierConfigManager; 23 import android.util.SparseArray; 24 25 import org.mockito.Mock; 26 import org.mockito.MockitoAnnotations; 27 28 import static org.mockito.Mockito.any; 29 import static org.mockito.Mockito.anyInt; 30 import static org.mockito.Mockito.doAnswer; 31 import static org.mockito.Mockito.doReturn; 32 import static org.mockito.Mockito.eq; 33 import static org.mockito.Mockito.mock; 34 import static org.mockito.Mockito.spy; 35 import static org.mockito.Mockito.when; 36 37 public abstract class CellBroadcastTest { 38 39 protected static String TAG; 40 41 private SparseArray<PersistableBundle> mBundles = new SparseArray<>(); 42 43 @Mock 44 Context mContext; 45 @Mock 46 CarrierConfigManager mCarrierConfigManager; 47 setUp(String tag)48 protected void setUp(String tag) throws Exception { 49 TAG = tag; 50 MockitoAnnotations.initMocks(this); 51 initContext(); 52 } 53 initContext()54 private void initContext() { 55 doReturn(mCarrierConfigManager).when(mContext). 56 getSystemService(eq(Context.CARRIER_CONFIG_SERVICE)); 57 } 58 carrierConfigSetStringArray(int subId, String key, String[] values)59 protected void carrierConfigSetStringArray(int subId, String key, String[] values) { 60 //doReturn(values).when(mCarrierConfigManager.getConfig(subId)).getStringArray(eq(key)); 61 if (mBundles.get(subId) == null) { 62 mBundles.put(subId, new PersistableBundle()); 63 } 64 mBundles.get(subId).putStringArray(key, values); 65 doReturn(mBundles.get(subId)).when(mCarrierConfigManager).getConfigForSubId(eq(subId)); 66 } 67 tearDown()68 protected void tearDown() throws Exception { 69 } 70 logd(String s)71 protected static void logd(String s) { 72 Log.d(TAG, s); 73 } 74 } 75