1 /* 2 * Copyright (C) 2018 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 package com.android.phone; 17 18 import static org.junit.Assert.assertFalse; 19 import static org.junit.Assert.assertTrue; 20 import static org.mockito.Mockito.when; 21 22 import android.content.Context; 23 import android.os.PersistableBundle; 24 import android.support.test.InstrumentationRegistry; 25 import android.support.test.runner.AndroidJUnit4; 26 import android.telephony.CarrierConfigManager; 27 28 import com.android.internal.telephony.Phone; 29 import com.android.internal.telephony.PhoneConstants; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.Mock; 35 import org.mockito.MockitoAnnotations; 36 37 @RunWith(AndroidJUnit4.class) 38 public class CdmaOptionsTest { 39 @Mock 40 private Phone mMockPhone; 41 42 private CdmaOptions mCdmaOptions; 43 private Context mContext; 44 45 @Before 46 public void setUp() { 47 MockitoAnnotations.initMocks(this); 48 mContext = InstrumentationRegistry.getContext(); 49 mCdmaOptions = new CdmaOptions(mMockPhone); 50 } 51 52 @Test 53 public void shouldAddApnExpandPreference_doesNotExpandOnGsm() { 54 when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM); 55 PersistableBundle bundle = new PersistableBundle(); 56 bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, true); 57 assertFalse(mCdmaOptions.shouldAddApnExpandPreference(bundle)); 58 59 when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_CDMA); 60 bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, false); 61 assertFalse(mCdmaOptions.shouldAddApnExpandPreference(bundle)); 62 63 when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_CDMA); 64 bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, true); 65 assertTrue(mCdmaOptions.shouldAddApnExpandPreference(bundle)); 66 } 67 } 68