Search in sources :

Example 11 with Device

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

the class ChannelLogDecorateTest method checkLogAttributes.

@Test
public void checkLogAttributes() throws DeviceInfoHelper.DeviceInfoException {
    mockStatic(DeviceInfoHelper.class);
    Device device = mock(Device.class);
    when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(device);
    mockStatic(IdHelper.class);
    Channel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mock(Persistence.class), mock(Ingestion.class));
    channel.addGroup("", 0, 0, 0, null);
    /* Test a log that should be decorated. */
    for (int i = 0; i < 3; i++) {
        Log log = mock(Log.class);
        channel.enqueue(log, "");
        verify(log).setDevice(device);
        verify(log).setToffset(anyLong());
    }
    /* Check cache was used, meaning only 1 call to generate a device. */
    verifyStatic();
    DeviceInfoHelper.getDeviceInfo(any(Context.class));
    /* Test a log that is already decorated. */
    Log log2 = mock(Log.class);
    when(log2.getDevice()).thenReturn(device);
    when(log2.getToffset()).thenReturn(123L);
    channel.enqueue(log2, "");
    verify(log2, never()).setDevice(any(Device.class));
    verify(log2, never()).setToffset(anyLong());
    /* Simulate update to wrapper SDK. */
    Device device2 = mock(Device.class);
    when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(device2);
    channel.invalidateDeviceCache();
    /* Generate some logs to verify device properties have been updated. */
    for (int i = 0; i < 3; i++) {
        Log log3 = mock(Log.class);
        channel.enqueue(log3, "");
        verify(log3).setDevice(device2);
        verify(log3).setToffset(anyLong());
    }
    /* Check only 1 device has been generated after cache invalidate. */
    verifyStatic(times(2));
    DeviceInfoHelper.getDeviceInfo(any(Context.class));
}
Also used : Context(android.content.Context) Persistence(com.microsoft.azure.mobile.persistence.Persistence) Log(com.microsoft.azure.mobile.ingestion.models.Log) Device(com.microsoft.azure.mobile.ingestion.models.Device) Ingestion(com.microsoft.azure.mobile.ingestion.Ingestion) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Device (com.microsoft.azure.mobile.ingestion.models.Device)11 Test (org.junit.Test)8 Context (android.content.Context)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 TelephonyManager (android.telephony.TelephonyManager)4 Build (android.os.Build)3 ActivityManager (android.app.ActivityManager)2 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)2 NonNull (android.support.annotation.NonNull)2 Display (android.view.Display)2 WindowManager (android.view.WindowManager)2 ManagedErrorLog (com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog)2 TestCrashException (com.microsoft.azure.mobile.crashes.model.TestCrashException)2 Log (com.microsoft.azure.mobile.ingestion.models.Log)2 Point (android.graphics.Point)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ArrayAdapter (android.widget.ArrayAdapter)1