[TeseCase] unify the getResourcesString
Bug: 173099559 Test: atest PreferredNetworkModePreferenceControllerTest (PASS) atest OpenNetworkSelectPagePreferenceControllerTest (PASS) atest MobilePlanPreferenceControllerTest (PASS) atest MobileDataPreferenceControllerTest (PASS) atest Enhanced4gLteSliceHelperTest (PASS) atest AutoSelectPreferenceControllerTest (PASS) Change-Id: I9a2e3d69cbd933a1282d51b7d8869e6a1ec4cb14
This commit is contained in:
@@ -19,11 +19,12 @@ package com.android.settings.network;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -42,12 +43,8 @@ public class MobilePlanPreferenceControllerTest {
|
||||
public void testNoProvisionStringFormattedCorrectly() {
|
||||
final String operator = "test_operator";
|
||||
|
||||
assertThat(resourceString("mobile_no_provisioning_url", operator))
|
||||
assertThat(
|
||||
ResourcesUtils.getResourcesString(mContext, "mobile_no_provisioning_url", operator))
|
||||
.contains(operator);
|
||||
}
|
||||
|
||||
public String resourceString(String name, Object value) {
|
||||
final Resources res = mContext.getResources();
|
||||
return res.getString(res.getIdentifier(name, "string", mContext.getPackageName()), value);
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.testutils.Utils;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -137,7 +137,7 @@ public class DefaultSubscriptionControllerTest {
|
||||
assertThat(entries[0]).isEqualTo("sub1");
|
||||
assertThat(entries[1]).isEqualTo("sub2");
|
||||
assertThat(entries[2]).isEqualTo(
|
||||
Utils.getResourceString(mContext, "calls_and_sms_ask_every_time"));
|
||||
ResourcesUtils.getResourcesString(mContext, "calls_and_sms_ask_every_time"));
|
||||
|
||||
final CharSequence[] entryValues = mListPreference.getEntryValues();
|
||||
assertThat(entryValues.length).isEqualTo(3);
|
||||
@@ -166,7 +166,7 @@ public class DefaultSubscriptionControllerTest {
|
||||
assertThat(entries[0]).isEqualTo("sub1");
|
||||
assertThat(entries[1]).isEqualTo("sub2");
|
||||
assertThat(entries[2]).isEqualTo(
|
||||
Utils.getResourceString(mContext, "calls_and_sms_ask_every_time"));
|
||||
ResourcesUtils.getResourcesString(mContext, "calls_and_sms_ask_every_time"));
|
||||
|
||||
final CharSequence[] entryValues = mListPreference.getEntryValues();
|
||||
assertThat(entryValues.length).isEqualTo(3);
|
||||
@@ -195,7 +195,7 @@ public class DefaultSubscriptionControllerTest {
|
||||
assertThat(entries[0]).isEqualTo("sub1");
|
||||
assertThat(entries[1]).isEqualTo("sub3");
|
||||
assertThat(entries[2]).isEqualTo(
|
||||
Utils.getResourceString(mContext, "calls_and_sms_ask_every_time"));
|
||||
ResourcesUtils.getResourcesString(mContext, "calls_and_sms_ask_every_time"));
|
||||
|
||||
final CharSequence[] entryValues = mListPreference.getEntryValues();
|
||||
assertThat(entryValues.length).isEqualTo(3);
|
||||
@@ -332,7 +332,7 @@ public class DefaultSubscriptionControllerTest {
|
||||
assertThat(entries[1].toString()).isEqualTo("sub2");
|
||||
assertThat(entries[2].toString()).isEqualTo("sub3");
|
||||
assertThat(entries[3].toString()).isEqualTo(
|
||||
Utils.getResourceString(mContext, "calls_and_sms_ask_every_time"));
|
||||
ResourcesUtils.getResourcesString(mContext, "calls_and_sms_ask_every_time"));
|
||||
assertThat(entryValues[0].toString()).isEqualTo("111");
|
||||
assertThat(entryValues[1].toString()).isEqualTo("222");
|
||||
assertThat(entryValues[2].toString()).isEqualTo("333");
|
||||
|
@@ -32,7 +32,6 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.ims.ProvisioningManager;
|
||||
|
||||
@@ -53,6 +52,7 @@ import com.android.settings.slices.SettingsSliceProvider;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
import com.android.settings.slices.SlicesFeatureProvider;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
@@ -203,7 +203,8 @@ public class Enhanced4gLteSliceHelperTest {
|
||||
|
||||
// Check the title
|
||||
final List<SliceItem> sliceItems = slice.getItems();
|
||||
assertTitle(sliceItems, resourceString("enhanced_4g_lte_mode_title"));
|
||||
assertTitle(sliceItems,
|
||||
ResourcesUtils.getResourcesString(mContext, "enhanced_4g_lte_mode_title"));
|
||||
}
|
||||
|
||||
private void testEnhanced4gLteSettingsToggleSlice(Slice slice) {
|
||||
@@ -228,7 +229,8 @@ public class Enhanced4gLteSliceHelperTest {
|
||||
|
||||
// Check the title
|
||||
final List<SliceItem> sliceItems = slice.getItems();
|
||||
assertTitle(sliceItems, resourceString("enhanced_4g_lte_mode_title"));
|
||||
assertTitle(sliceItems,
|
||||
ResourcesUtils.getResourcesString(mContext, "enhanced_4g_lte_mode_title"));
|
||||
}
|
||||
|
||||
private PendingIntent getBroadcastIntent(String action) {
|
||||
@@ -287,9 +289,4 @@ public class Enhanced4gLteSliceHelperTest {
|
||||
return mQueryImsState;
|
||||
}
|
||||
}
|
||||
|
||||
public String resourceString(String name) {
|
||||
final Resources res = mContext.getResources();
|
||||
return res.getString(res.getIdentifier(name, "string", mContext.getPackageName()));
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -40,6 +39,8 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -169,8 +170,9 @@ public class MobileDataPreferenceControllerTest {
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(resourceString("mobile_data_settings_summary_auto_switch"));
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext,
|
||||
"mobile_data_settings_summary_auto_switch"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,12 +183,7 @@ public class MobileDataPreferenceControllerTest {
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(resourceString("mobile_data_settings_summary"));
|
||||
}
|
||||
|
||||
public String resourceString(String name) {
|
||||
final Resources res = mContext.getResources();
|
||||
return res.getString(res.getIdentifier(name, "string", mContext.getPackageName()));
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "mobile_data_settings_summary"));
|
||||
}
|
||||
}
|
||||
|
@@ -38,8 +38,8 @@ import androidx.preference.ListPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -73,7 +73,8 @@ public class PreferredNetworkModePreferenceControllerTest {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(mCarrierConfigManager);
|
||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
||||
mCarrierConfigManager);
|
||||
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||
@@ -91,7 +92,7 @@ public class PreferredNetworkModePreferenceControllerTest {
|
||||
@After
|
||||
public void tearDown() {
|
||||
Settings.Global.putInt(
|
||||
mContext.getContentResolver(), Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0);
|
||||
mContext.getContentResolver(), Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,7 +143,8 @@ public class PreferredNetworkModePreferenceControllerTest {
|
||||
assertThat(mPreference.getValue()).isEqualTo(
|
||||
String.valueOf(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
resourceString("preferred_network_mode_tdscdma_gsm_wcdma_summary"));
|
||||
ResourcesUtils.getResourcesString(mContext,
|
||||
"preferred_network_mode_tdscdma_gsm_wcdma_summary"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,7 +163,7 @@ public class PreferredNetworkModePreferenceControllerTest {
|
||||
@Test
|
||||
public void onPreferenceChange_updateFail() {
|
||||
doReturn(false).when(mTelephonyManager).setPreferredNetworkTypeBitmask(
|
||||
getRafFromNetworkType(TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA));
|
||||
getRafFromNetworkType(TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA));
|
||||
|
||||
mController.onPreferenceChange(mPreference,
|
||||
String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA));
|
||||
@@ -170,12 +172,4 @@ public class PreferredNetworkModePreferenceControllerTest {
|
||||
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isNotEqualTo(
|
||||
TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA);
|
||||
}
|
||||
|
||||
public int resourceId(String type, String name) {
|
||||
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
|
||||
}
|
||||
|
||||
public String resourceString(String name) {
|
||||
return mContext.getResources().getString(resourceId("string", name));
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,8 @@ import androidx.preference.SwitchPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -128,7 +130,7 @@ public class AutoSelectPreferenceControllerTest {
|
||||
|
||||
assertThat(mSwitchPreference.isEnabled()).isFalse();
|
||||
assertThat(mSwitchPreference.getSummary()).isEqualTo(
|
||||
resourceString("manual_mode_disallowed_summary",
|
||||
ResourcesUtils.getResourcesString(mContext, "manual_mode_disallowed_summary",
|
||||
mTelephonyManager.getSimOperatorName()));
|
||||
}
|
||||
|
||||
@@ -139,12 +141,4 @@ public class AutoSelectPreferenceControllerTest {
|
||||
// Should not crash
|
||||
mController.init(mLifecycle, SUB_ID);
|
||||
}
|
||||
|
||||
public int resourceId(String type, String name) {
|
||||
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
|
||||
}
|
||||
|
||||
public String resourceString(String name, Object value) {
|
||||
return mContext.getResources().getString(resourceId("string", name), value);
|
||||
}
|
||||
}
|
||||
|
@@ -34,6 +34,8 @@ import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -118,14 +120,7 @@ public class OpenNetworkSelectPagePreferenceControllerTest {
|
||||
public void getSummary_notInService_returnDisconnect() {
|
||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||
|
||||
assertThat(mController.getSummary()).isEqualTo(resourceString("network_disconnected"));
|
||||
}
|
||||
|
||||
public int resourceId(String type, String name) {
|
||||
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
|
||||
}
|
||||
|
||||
public String resourceString(String name) {
|
||||
return mContext.getResources().getString(resourceId("string", name));
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "network_disconnected"));
|
||||
}
|
||||
}
|
||||
|
@@ -17,12 +17,16 @@ package com.android.settings.testutils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public final class Utils {
|
||||
public static int getResourceId(Context context, String type, String name) {
|
||||
public final class ResourcesUtils {
|
||||
public static int getResourcesId(Context context, String type, String name) {
|
||||
return context.getResources().getIdentifier(name, type, context.getPackageName());
|
||||
}
|
||||
|
||||
public static String getResourceString(Context context, String name) {
|
||||
return context.getResources().getString(getResourceId(context, "string", name));
|
||||
public static String getResourcesString(Context context, String name) {
|
||||
return context.getResources().getString(getResourcesId(context, "string", name));
|
||||
}
|
||||
|
||||
public static String getResourcesString(Context context, String name, Object value) {
|
||||
return context.getResources().getString(getResourcesId(context, "string", name), value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user