@Test public void getDeviceInfoMissingCarrierInfo() throws DeviceInfoHelper.DeviceInfoException, PackageManager.NameNotFoundException { /* Mocking instances. */ Context contextMock = mock(Context.class); PackageManager packageManagerMock = mock(PackageManager.class); WindowManager windowManagerMock = mock(WindowManager.class); mockStatic(AppCenterLog.class); /* Delegates to mock instances. */ when(contextMock.getPackageManager()).thenReturn(packageManagerMock); when(contextMock.getSystemService(Context.TELEPHONY_SERVICE)).thenThrow(new RuntimeException()); when(contextMock.getSystemService(Context.WINDOW_SERVICE)).thenReturn(windowManagerMock); //noinspection WrongConstant when(packageManagerMock.getPackageInfo(anyString(), anyInt())).thenReturn(mock(PackageInfo.class)); when(windowManagerMock.getDefaultDisplay()).thenReturn(mock(Display.class)); /* Verify. */ Device device = DeviceInfoHelper.getDeviceInfo(contextMock); assertNull(device.getCarrierCountry()); assertNull(device.getCarrierName()); verifyStatic(); AppCenterLog.error(eq(AppCenter.LOG_TAG), anyString(), any(Exception.class)); }
@Test public void getDeviceInfoEmptyCarrierInfo() throws DeviceInfoHelper.DeviceInfoException, PackageManager.NameNotFoundException { /* Mocking instances. */ Context contextMock = mock(Context.class); PackageManager packageManagerMock = mock(PackageManager.class); /* Delegates to mock instances. */ when(contextMock.getPackageManager()).thenReturn(packageManagerMock); //noinspection WrongConstant when(packageManagerMock.getPackageInfo(anyString(), anyInt())).thenReturn(mock(PackageInfo.class)); TelephonyManager telephonyManager = mock(TelephonyManager.class); when(telephonyManager.getNetworkCountryIso()).thenReturn(""); when(telephonyManager.getNetworkOperatorName()).thenReturn(""); when(contextMock.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(telephonyManager); mockStatic(TextUtils.class); when(TextUtils.isEmpty(anyString())).thenReturn(true); /* Verify. */ Device device = DeviceInfoHelper.getDeviceInfo(contextMock); assertNull(device.getCarrierCountry()); assertNull(device.getCarrierName()); }
assertEquals(appNamespace, device.getAppNamespace()); assertEquals(carrierCountry, device.getCarrierCountry()); assertEquals(carrierName, device.getCarrierName()); assertEquals(locale.toString(), device.getLocale()); assertEquals(model, device.getModel());
dest.getExt().getNet().setProvider(device.getCarrierName());
@Override public void write(JSONStringer writer) throws JSONException { super.write(writer); writer.key(SDK_NAME).value(getSdkName()); writer.key(SDK_VERSION).value(getSdkVersion()); writer.key(MODEL).value(getModel()); writer.key(OEM_NAME).value(getOemName()); writer.key(OS_NAME).value(getOsName()); writer.key(OS_VERSION).value(getOsVersion()); JSONUtils.write(writer, OS_BUILD, getOsBuild()); JSONUtils.write(writer, OS_API_LEVEL, getOsApiLevel()); writer.key(LOCALE).value(getLocale()); writer.key(TIME_ZONE_OFFSET).value(getTimeZoneOffset()); writer.key(SCREEN_SIZE).value(getScreenSize()); writer.key(APP_VERSION).value(getAppVersion()); JSONUtils.write(writer, CARRIER_NAME, getCarrierName()); JSONUtils.write(writer, CARRIER_COUNTRY, getCarrierCountry()); writer.key(APP_BUILD).value(getAppBuild()); JSONUtils.write(writer, APP_NAMESPACE, getAppNamespace()); }