Search in sources :

Example 1 with WrapperSdk

use of com.microsoft.appcenter.ingestion.models.WrapperSdk in project mobile-center-sdk-android by Microsoft.

the class AppCenterTest method setWrapperSdkTest.

@Test
public void setWrapperSdkTest() {
    /* Call method. */
    WrapperSdk wrapperSdk = new WrapperSdk();
    AppCenter.setWrapperSdk(wrapperSdk);
    /* Check propagation. */
    verifyStatic();
    DeviceInfoHelper.setWrapperSdk(wrapperSdk);
    /* Since the channel was not created when setting wrapper, no need to refresh channel after start. */
    AppCenter.start(mApplication, DUMMY_APP_SECRET, DummyService.class);
    verify(mChannel, never()).invalidateDeviceCache();
    /* Update wrapper SDK and check channel refreshed. */
    wrapperSdk = new WrapperSdk();
    AppCenter.setWrapperSdk(wrapperSdk);
    verify(mChannel).invalidateDeviceCache();
}
Also used : WrapperSdk(com.microsoft.appcenter.ingestion.models.WrapperSdk) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with WrapperSdk

use of com.microsoft.appcenter.ingestion.models.WrapperSdk in project mobile-center-sdk-android by Microsoft.

the class DeviceInfoHelperTest method getDeviceInfo.

@Test
public void getDeviceInfo() throws PackageManager.NameNotFoundException, DeviceInfoHelper.DeviceInfoException {
    /* Mock data. */
    final String appVersion = "1.0";
    final String appBuild = "1";
    // noinspection SpellCheckingInspection
    final String appNamespace = "com.contoso.app";
    final String carrierCountry = "us";
    final String carrierName = "mock-service";
    final Locale locale = Locale.KOREA;
    final String model = "mock-model";
    final String oemName = "mock-manufacture";
    final Integer osApiLevel = 23;
    final String osName = "Android";
    final String osVersion = "mock-version";
    final String osBuild = "mock-os-build";
    final String screenSizeLandscape = "100x200";
    final String screenSizePortrait = "200x100";
    final TimeZone timeZone = TimeZone.getTimeZone("KST");
    final Integer timeZoneOffset = timeZone.getOffset(System.currentTimeMillis());
    Locale.setDefault(locale);
    TimeZone.setDefault(timeZone);
    /* Mocking instances. */
    Context contextMock = mock(Context.class);
    PackageManager packageManagerMock = mock(PackageManager.class);
    PackageInfo packageInfoMock = mock(PackageInfo.class);
    WindowManager windowManagerMock = mock(WindowManager.class);
    TelephonyManager telephonyManagerMock = mock(TelephonyManager.class);
    Display displayMock = mock(Display.class);
    /* Delegates to mock instances. */
    when(contextMock.getPackageName()).thenReturn(appNamespace);
    when(contextMock.getPackageManager()).thenReturn(packageManagerMock);
    // noinspection WrongConstant
    when(contextMock.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn(telephonyManagerMock);
    // noinspection WrongConstant
    when(contextMock.getSystemService(eq(Context.WINDOW_SERVICE))).thenReturn(windowManagerMock);
    // noinspection WrongConstant
    when(packageManagerMock.getPackageInfo(anyString(), eq(0))).thenReturn(packageInfoMock);
    when(telephonyManagerMock.getNetworkCountryIso()).thenReturn(carrierCountry);
    when(telephonyManagerMock.getNetworkOperatorName()).thenReturn(carrierName);
    when(windowManagerMock.getDefaultDisplay()).thenReturn(displayMock);
    when(displayMock.getRotation()).thenReturn(Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, Surface.ROTATION_270);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            /* DO NOT call set method and assign values directly to variables. */
            ((Point) args[0]).x = 100;
            ((Point) args[0]).y = 200;
            return null;
        }
    }).when(displayMock).getSize(any(Point.class));
    /* Sets values of fields for static classes. */
    Whitebox.setInternalState(packageInfoMock, "versionName", appVersion);
    Whitebox.setInternalState(packageInfoMock, "versionCode", Integer.parseInt(appBuild));
    Whitebox.setInternalState(Build.class, "MODEL", model);
    Whitebox.setInternalState(Build.class, "MANUFACTURER", oemName);
    Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", osApiLevel);
    Whitebox.setInternalState(Build.class, "ID", osBuild);
    Whitebox.setInternalState(Build.VERSION.class, "RELEASE", osVersion);
    /* First call */
    Device device = DeviceInfoHelper.getDeviceInfo(contextMock);
    /* Verify device information. */
    assertNull(device.getWrapperSdkName());
    assertNull(device.getWrapperSdkVersion());
    assertEquals(BuildConfig.VERSION_NAME, device.getSdkVersion());
    assertEquals(appVersion, device.getAppVersion());
    assertEquals(appBuild, device.getAppBuild());
    assertEquals(appNamespace, device.getAppNamespace());
    assertEquals(carrierCountry, device.getCarrierCountry());
    assertEquals(carrierName, device.getCarrierName());
    assertEquals(locale.toString(), device.getLocale());
    assertEquals(model, device.getModel());
    assertEquals(oemName, device.getOemName());
    assertEquals(osApiLevel, device.getOsApiLevel());
    assertEquals(osName, device.getOsName());
    assertEquals(osVersion, device.getOsVersion());
    assertEquals(osBuild, device.getOsBuild());
    assertEquals(screenSizeLandscape, device.getScreenSize());
    assertEquals(timeZoneOffset, device.getTimeZoneOffset());
    /* Verify screen size based on different orientations (Surface.ROTATION_90). */
    device = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(screenSizePortrait, device.getScreenSize());
    /* Verify screen size based on different orientations (Surface.ROTATION_180). */
    device = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(screenSizeLandscape, device.getScreenSize());
    /* Verify screen size based on different orientations (Surface.ROTATION_270). */
    device = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(screenSizePortrait, device.getScreenSize());
    /* Make sure screen size is verified for all orientations. */
    verify(displayMock, times(4)).getRotation();
    /* Set wrapper sdk information. */
    WrapperSdk wrapperSdk = new WrapperSdk();
    wrapperSdk.setWrapperSdkVersion("1.2.3.4");
    wrapperSdk.setWrapperSdkName("ReactNative");
    wrapperSdk.setWrapperRuntimeVersion("4.13");
    wrapperSdk.setLiveUpdateReleaseLabel("2.0.3-beta2");
    wrapperSdk.setLiveUpdateDeploymentKey("staging");
    wrapperSdk.setLiveUpdatePackageHash("aa896f791b26a7f464c0f62b0ba69f2b");
    DeviceInfoHelper.setWrapperSdk(wrapperSdk);
    Device device2 = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(wrapperSdk.getWrapperSdkVersion(), device2.getWrapperSdkVersion());
    assertEquals(wrapperSdk.getWrapperSdkName(), device2.getWrapperSdkName());
    assertEquals(wrapperSdk.getWrapperRuntimeVersion(), device2.getWrapperRuntimeVersion());
    assertEquals(wrapperSdk.getLiveUpdateReleaseLabel(), device2.getLiveUpdateReleaseLabel());
    assertEquals(wrapperSdk.getLiveUpdateDeploymentKey(), device2.getLiveUpdateDeploymentKey());
    assertEquals(wrapperSdk.getLiveUpdatePackageHash(), device2.getLiveUpdatePackageHash());
    /* Check non wrapped sdk information are still generated correctly. */
    device2.setWrapperSdkVersion(null);
    device2.setWrapperSdkName(null);
    device2.setWrapperRuntimeVersion(null);
    device2.setLiveUpdateReleaseLabel(null);
    device2.setLiveUpdateDeploymentKey(null);
    device2.setLiveUpdatePackageHash(null);
    assertEquals(device, device2);
    /* Remove wrapper SDK information. */
    DeviceInfoHelper.setWrapperSdk(null);
    assertEquals(device, DeviceInfoHelper.getDeviceInfo(contextMock));
}
Also used : Locale(java.util.Locale) Context(android.content.Context) PackageInfo(android.content.pm.PackageInfo) Device(com.microsoft.appcenter.ingestion.models.Device) Mockito.anyString(org.mockito.Mockito.anyString) Point(android.graphics.Point) WindowManager(android.view.WindowManager) TimeZone(java.util.TimeZone) PackageManager(android.content.pm.PackageManager) TelephonyManager(android.telephony.TelephonyManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Build(android.os.Build) WrapperSdk(com.microsoft.appcenter.ingestion.models.WrapperSdk) Display(android.view.Display) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with WrapperSdk

use of com.microsoft.appcenter.ingestion.models.WrapperSdk in project AppCenter-SDK-Android by Microsoft.

the class DeviceInfoHelperTest method getDeviceInfo.

@Test
public void getDeviceInfo() throws PackageManager.NameNotFoundException, DeviceInfoHelper.DeviceInfoException {
    /* Mock data. */
    final String appVersion = "1.0";
    final String appBuild = "1";
    // noinspection SpellCheckingInspection
    final String appNamespace = "com.contoso.app";
    final String carrierCountry = "us";
    final String carrierName = "mock-service";
    final Locale locale = Locale.KOREA;
    final String model = "mock-model";
    final String oemName = "mock-manufacture";
    final Integer osApiLevel = 23;
    final String osName = "Android";
    final String osVersion = "mock-version";
    final String osBuild = "mock-os-build";
    final String screenSizeLandscape = "100x200";
    final String screenSizePortrait = "200x100";
    final TimeZone timeZone = TimeZone.getTimeZone("KST");
    final Integer timeZoneOffset = timeZone.getOffset(System.currentTimeMillis());
    Locale.setDefault(locale);
    TimeZone.setDefault(timeZone);
    /* Mocking instances. */
    Context contextMock = mock(Context.class);
    PackageManager packageManagerMock = mock(PackageManager.class);
    PackageInfo packageInfoMock = mock(PackageInfo.class);
    WindowManager windowManagerMock = mock(WindowManager.class);
    TelephonyManager telephonyManagerMock = mock(TelephonyManager.class);
    Display displayMock = mock(Display.class);
    /* Delegates to mock instances. */
    when(contextMock.getPackageName()).thenReturn(appNamespace);
    when(contextMock.getPackageManager()).thenReturn(packageManagerMock);
    // noinspection WrongConstant
    when(contextMock.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn(telephonyManagerMock);
    // noinspection WrongConstant
    when(contextMock.getSystemService(eq(Context.WINDOW_SERVICE))).thenReturn(windowManagerMock);
    // noinspection WrongConstant
    when(packageManagerMock.getPackageInfo(anyString(), eq(0))).thenReturn(packageInfoMock);
    when(telephonyManagerMock.getNetworkCountryIso()).thenReturn(carrierCountry);
    when(telephonyManagerMock.getNetworkOperatorName()).thenReturn(carrierName);
    when(windowManagerMock.getDefaultDisplay()).thenReturn(displayMock);
    when(displayMock.getRotation()).thenReturn(Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, Surface.ROTATION_270);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            /* DO NOT call set method and assign values directly to variables. */
            ((Point) args[0]).x = 100;
            ((Point) args[0]).y = 200;
            return null;
        }
    }).when(displayMock).getSize(any(Point.class));
    /* Sets values of fields for static classes. */
    Whitebox.setInternalState(packageInfoMock, "versionName", appVersion);
    Whitebox.setInternalState(packageInfoMock, "versionCode", Integer.parseInt(appBuild));
    Whitebox.setInternalState(Build.class, "MODEL", model);
    Whitebox.setInternalState(Build.class, "MANUFACTURER", oemName);
    Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", osApiLevel);
    Whitebox.setInternalState(Build.class, "ID", osBuild);
    Whitebox.setInternalState(Build.VERSION.class, "RELEASE", osVersion);
    /* First call */
    Device device = DeviceInfoHelper.getDeviceInfo(contextMock);
    /* Verify device information. */
    assertNull(device.getWrapperSdkName());
    assertNull(device.getWrapperSdkVersion());
    assertEquals(BuildConfig.VERSION_NAME, device.getSdkVersion());
    assertEquals(appVersion, device.getAppVersion());
    assertEquals(appBuild, device.getAppBuild());
    assertEquals(appNamespace, device.getAppNamespace());
    assertEquals(carrierCountry, device.getCarrierCountry());
    assertEquals(carrierName, device.getCarrierName());
    assertEquals(locale.toString(), device.getLocale());
    assertEquals(model, device.getModel());
    assertEquals(oemName, device.getOemName());
    assertEquals(osApiLevel, device.getOsApiLevel());
    assertEquals(osName, device.getOsName());
    assertEquals(osVersion, device.getOsVersion());
    assertEquals(osBuild, device.getOsBuild());
    assertEquals(screenSizeLandscape, device.getScreenSize());
    assertEquals(timeZoneOffset, device.getTimeZoneOffset());
    /* Verify screen size based on different orientations (Surface.ROTATION_90). */
    device = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(screenSizePortrait, device.getScreenSize());
    /* Verify screen size based on different orientations (Surface.ROTATION_180). */
    device = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(screenSizeLandscape, device.getScreenSize());
    /* Verify screen size based on different orientations (Surface.ROTATION_270). */
    device = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(screenSizePortrait, device.getScreenSize());
    /* Make sure screen size is verified for all orientations. */
    verify(displayMock, times(4)).getRotation();
    /* Set wrapper sdk information. */
    WrapperSdk wrapperSdk = new WrapperSdk();
    wrapperSdk.setWrapperSdkVersion("1.2.3.4");
    wrapperSdk.setWrapperSdkName("ReactNative");
    wrapperSdk.setWrapperRuntimeVersion("4.13");
    wrapperSdk.setLiveUpdateReleaseLabel("2.0.3-beta2");
    wrapperSdk.setLiveUpdateDeploymentKey("staging");
    wrapperSdk.setLiveUpdatePackageHash("aa896f791b26a7f464c0f62b0ba69f2b");
    DeviceInfoHelper.setWrapperSdk(wrapperSdk);
    Device device2 = DeviceInfoHelper.getDeviceInfo(contextMock);
    assertEquals(wrapperSdk.getWrapperSdkVersion(), device2.getWrapperSdkVersion());
    assertEquals(wrapperSdk.getWrapperSdkName(), device2.getWrapperSdkName());
    assertEquals(wrapperSdk.getWrapperRuntimeVersion(), device2.getWrapperRuntimeVersion());
    assertEquals(wrapperSdk.getLiveUpdateReleaseLabel(), device2.getLiveUpdateReleaseLabel());
    assertEquals(wrapperSdk.getLiveUpdateDeploymentKey(), device2.getLiveUpdateDeploymentKey());
    assertEquals(wrapperSdk.getLiveUpdatePackageHash(), device2.getLiveUpdatePackageHash());
    /* Check non wrapped sdk information are still generated correctly. */
    device2.setWrapperSdkVersion(null);
    device2.setWrapperSdkName(null);
    device2.setWrapperRuntimeVersion(null);
    device2.setLiveUpdateReleaseLabel(null);
    device2.setLiveUpdateDeploymentKey(null);
    device2.setLiveUpdatePackageHash(null);
    assertEquals(device, device2);
    /* Remove wrapper SDK information. */
    DeviceInfoHelper.setWrapperSdk(null);
    assertEquals(device, DeviceInfoHelper.getDeviceInfo(contextMock));
}
Also used : Locale(java.util.Locale) Context(android.content.Context) PackageInfo(android.content.pm.PackageInfo) Device(com.microsoft.appcenter.ingestion.models.Device) Mockito.anyString(org.mockito.Mockito.anyString) Point(android.graphics.Point) WindowManager(android.view.WindowManager) TimeZone(java.util.TimeZone) PackageManager(android.content.pm.PackageManager) TelephonyManager(android.telephony.TelephonyManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Build(android.os.Build) WrapperSdk(com.microsoft.appcenter.ingestion.models.WrapperSdk) Display(android.view.Display) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with WrapperSdk

use of com.microsoft.appcenter.ingestion.models.WrapperSdk in project AppCenter-SDK-Android by Microsoft.

the class AppCenterTest method setWrapperSdkTest.

@Test
public void setWrapperSdkTest() throws Exception {
    /* Call method. */
    WrapperSdk wrapperSdk = new WrapperSdk();
    AppCenter.setWrapperSdk(wrapperSdk);
    /* Check propagation. */
    verifyStatic();
    DeviceInfoHelper.setWrapperSdk(wrapperSdk);
    /* Since the channel was not created when setting wrapper, no need to refresh channel after start. */
    AppCenter.start(mApplication, DUMMY_APP_SECRET, DummyService.class);
    verify(mChannel, never()).invalidateDeviceCache();
    /* Update wrapper SDK and check channel refreshed. */
    wrapperSdk = new WrapperSdk();
    AppCenter.setWrapperSdk(wrapperSdk);
    verify(mChannel).invalidateDeviceCache();
}
Also used : WrapperSdk(com.microsoft.appcenter.ingestion.models.WrapperSdk) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with WrapperSdk

use of com.microsoft.appcenter.ingestion.models.WrapperSdk in project mobile-center-sdk-android by Microsoft.

the class DeviceInfoHelperTest method deviceInfo.

@Test
public void deviceInfo() throws PackageManager.NameNotFoundException, DeviceInfoHelper.DeviceInfoException {
    /* Mock system calls. */
    // noinspection WrongConstant
    when(mContext.getSystemService(eq(Context.DISPLAY_SERVICE))).thenReturn(mDisplayManager);
    when(mDisplayManager.getDisplay(anyInt())).thenReturn(mDisplay);
    // noinspection WrongConstant
    when(mContext.getResources()).thenReturn(mResources);
    // noinspection WrongConstant
    when(mResources.getDisplayMetrics()).thenReturn(mDisplayMetrics);
    mDisplayMetrics.widthPixels = SCREEN_WIDTH;
    mDisplayMetrics.heightPixels = SCREEN_HEIGHT;
    /* Mock data. */
    final Integer osApiLevel = 21;
    final String appVersion = "1.0";
    final String appBuild = "1";
    final String appNamespace = "com.contoso.app";
    final String carrierCountry = "us";
    final String carrierName = "mock-service";
    final Locale locale = Locale.KOREA;
    final String model = "mock-model";
    final String oemName = "mock-manufacture";
    final String osName = "Android";
    final String osVersion = "mock-version";
    final String osBuild = "mock-os-build";
    final String screenSizeLandscape = "100x200";
    final String screenSizePortrait = "200x100";
    final TimeZone timeZone = TimeZone.getTimeZone("KST");
    final Integer timeZoneOffset = timeZone.getOffset(System.currentTimeMillis());
    Locale.setDefault(locale);
    TimeZone.setDefault(timeZone);
    /* Delegates to mock instances. */
    when(mContext.getPackageName()).thenReturn(appNamespace);
    // noinspection WrongConstant
    when(mContext.getSystemService(eq(Context.TELEPHONY_SERVICE))).thenReturn(mTelephonyManager);
    // noinspection WrongConstant
    when(mPackageManager.getPackageInfo(anyString(), eq(0))).thenReturn(mPackageInfo);
    when(mTelephonyManager.getNetworkCountryIso()).thenReturn(carrierCountry);
    when(mTelephonyManager.getNetworkOperatorName()).thenReturn(carrierName);
    when(mDisplay.getRotation()).thenReturn(Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, Surface.ROTATION_270);
    /* Sets values of fields for static classes. */
    Whitebox.setInternalState(mPackageInfo, "versionName", appVersion);
    Whitebox.setInternalState(mPackageInfo, "versionCode", Integer.parseInt(appBuild));
    Whitebox.setInternalState(Build.class, "MODEL", model);
    Whitebox.setInternalState(Build.class, "MANUFACTURER", oemName);
    Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", osApiLevel);
    Whitebox.setInternalState(Build.class, "ID", osBuild);
    Whitebox.setInternalState(Build.VERSION.class, "RELEASE", osVersion);
    /* First call */
    Device device = DeviceInfoHelper.getDeviceInfo(mContext);
    /* Verify device information. */
    assertNull(device.getWrapperSdkName());
    assertNull(device.getWrapperSdkVersion());
    assertEquals(BuildConfig.VERSION_NAME, device.getSdkVersion());
    assertEquals(appVersion, device.getAppVersion());
    assertEquals(appBuild, device.getAppBuild());
    assertEquals(appNamespace, device.getAppNamespace());
    assertEquals(carrierCountry, device.getCarrierCountry());
    assertEquals(carrierName, device.getCarrierName());
    assertEquals(locale.toString(), device.getLocale());
    assertEquals(model, device.getModel());
    assertEquals(oemName, device.getOemName());
    assertEquals(osApiLevel, device.getOsApiLevel());
    assertEquals(osName, device.getOsName());
    assertEquals(osVersion, device.getOsVersion());
    assertEquals(osBuild, device.getOsBuild());
    assertEquals(screenSizeLandscape, device.getScreenSize());
    assertEquals(timeZoneOffset, device.getTimeZoneOffset());
    /* Verify screen size based on different orientations (Surface.ROTATION_90). */
    device = DeviceInfoHelper.getDeviceInfo(mContext);
    assertEquals(screenSizePortrait, device.getScreenSize());
    /* Verify screen size based on different orientations (Surface.ROTATION_180). */
    device = DeviceInfoHelper.getDeviceInfo(mContext);
    assertEquals(screenSizeLandscape, device.getScreenSize());
    /* Verify screen size based on different orientations (Surface.ROTATION_270). */
    device = DeviceInfoHelper.getDeviceInfo(mContext);
    assertEquals(screenSizePortrait, device.getScreenSize());
    /* Make sure screen size is verified for all orientations. */
    verify(mDisplay, times(4)).getRotation();
    /* Set wrapper sdk information. */
    WrapperSdk wrapperSdk = new WrapperSdk();
    wrapperSdk.setWrapperSdkVersion("1.2.3.4");
    wrapperSdk.setWrapperSdkName("ReactNative");
    wrapperSdk.setWrapperRuntimeVersion("4.13");
    wrapperSdk.setLiveUpdateReleaseLabel("2.0.3-beta2");
    wrapperSdk.setLiveUpdateDeploymentKey("staging");
    wrapperSdk.setLiveUpdatePackageHash("aa896f791b26a7f464c0f62b0ba69f2b");
    DeviceInfoHelper.setWrapperSdk(wrapperSdk);
    Device device2 = DeviceInfoHelper.getDeviceInfo(mContext);
    assertEquals(wrapperSdk.getWrapperSdkVersion(), device2.getWrapperSdkVersion());
    assertEquals(wrapperSdk.getWrapperSdkName(), device2.getWrapperSdkName());
    assertEquals(wrapperSdk.getWrapperRuntimeVersion(), device2.getWrapperRuntimeVersion());
    assertEquals(wrapperSdk.getLiveUpdateReleaseLabel(), device2.getLiveUpdateReleaseLabel());
    assertEquals(wrapperSdk.getLiveUpdateDeploymentKey(), device2.getLiveUpdateDeploymentKey());
    assertEquals(wrapperSdk.getLiveUpdatePackageHash(), device2.getLiveUpdatePackageHash());
    /* Check non wrapped sdk information are still generated correctly. */
    device2.setWrapperSdkVersion(null);
    device2.setWrapperSdkName(null);
    device2.setWrapperRuntimeVersion(null);
    device2.setLiveUpdateReleaseLabel(null);
    device2.setLiveUpdateDeploymentKey(null);
    device2.setLiveUpdatePackageHash(null);
    assertEquals(device, device2);
    /* Remove wrapper SDK information. */
    DeviceInfoHelper.setWrapperSdk(null);
    assertEquals(device, DeviceInfoHelper.getDeviceInfo(mContext));
    /* Verify the right API was called to get a screen size. */
    verify(mContext, atLeastOnce()).getSystemService(eq(Context.DISPLAY_SERVICE));
    verify(mContext, atLeastOnce()).getResources();
    verify(mResources, atLeastOnce()).getDisplayMetrics();
    // noinspection deprecation
    verify(mDisplay, never()).getSize(any(Point.class));
    verify(mContext, never()).getSystemService(eq(Context.WINDOW_SERVICE));
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) Build(android.os.Build) Device(com.microsoft.appcenter.ingestion.models.Device) WrapperSdk(com.microsoft.appcenter.ingestion.models.WrapperSdk) Mockito.anyString(org.mockito.Mockito.anyString) Point(android.graphics.Point) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

WrapperSdk (com.microsoft.appcenter.ingestion.models.WrapperSdk)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Point (android.graphics.Point)3 Build (android.os.Build)3 Device (com.microsoft.appcenter.ingestion.models.Device)3 Locale (java.util.Locale)3 TimeZone (java.util.TimeZone)3 Mockito.anyString (org.mockito.Mockito.anyString)3 Context (android.content.Context)2 PackageInfo (android.content.pm.PackageInfo)2 PackageManager (android.content.pm.PackageManager)2 TelephonyManager (android.telephony.TelephonyManager)2 Display (android.view.Display)2 WindowManager (android.view.WindowManager)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2