Merge "Synced the code from master branch" am: 64efbe1240
am: 418ef9973e
Change-Id: I430b9c45d007de822c87733b1eb4fc71b36ff23c
This commit is contained in:
@@ -70,8 +70,11 @@ import android.telephony.euicc.EuiccManager;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceInfoUtils;
|
||||
import com.android.settingslib.DeviceInfoUtils;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -80,10 +83,12 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceInfoUtils.class})
|
||||
public class SimStatusDialogControllerTest {
|
||||
|
||||
@Mock
|
||||
@@ -120,11 +125,11 @@ public class SimStatusDialogControllerTest {
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mController = spy(new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */));
|
||||
ShadowDeviceInfoUtils.setPhoneNumber("");
|
||||
doReturn(mServiceState).when(mController).getCurrentServiceState();
|
||||
doReturn(0).when(mSignalStrength).getDbm();
|
||||
doReturn(0).when(mSignalStrength).getAsuLevel();
|
||||
doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
|
||||
doReturn("").when(mController).getPhoneNumber();
|
||||
doReturn(mSignalStrength).when(mController).getSignalStrength();
|
||||
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
|
||||
|
||||
@@ -147,6 +152,11 @@ public class SimStatusDialogControllerTest {
|
||||
shadowPackageManager.addPackage(sysUIPackageInfo);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowDeviceInfoUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_updateNetworkProviderWithFoobarCarrier_shouldUpdateCarrierWithFoobar() {
|
||||
final CharSequence carrierName = "foobar";
|
||||
@@ -159,8 +169,10 @@ public class SimStatusDialogControllerTest {
|
||||
|
||||
@Test
|
||||
public void initialize_updatePhoneNumberWith1111111111_shouldUpdatePhoneNumber() {
|
||||
final String phoneNumber = "1111111111";
|
||||
doReturn(phoneNumber).when(mController).getPhoneNumber();
|
||||
ShadowDeviceInfoUtils.setPhoneNumber("1111111111");
|
||||
|
||||
final String phoneNumber = DeviceInfoUtils.getBidiFormattedPhoneNumber(mContext,
|
||||
mSubscriptionInfo);
|
||||
|
||||
mController.initialize();
|
||||
|
||||
|
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@Implements(com.android.settingslib.DeviceInfoUtils.class)
|
||||
public class ShadowDeviceInfoUtils {
|
||||
private static String sPhoneNumber;
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sPhoneNumber = "";
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static String getBidiFormattedPhoneNumber(Context context,
|
||||
SubscriptionInfo subscriptionInfo) {
|
||||
return sPhoneNumber;
|
||||
}
|
||||
|
||||
public static void setPhoneNumber(String phoneNumber) {
|
||||
sPhoneNumber = phoneNumber;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user