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));
}
Aggregations