use of com.microsoft.appcenter.ingestion.models.json.LogSerializer in project mobile-center-sdk-android by Microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrash.
@Test
public void saveWrapperSdkCrash() throws JSONException, IOException {
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
byte[] data = new byte[] { 'd' };
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic();
StorageHelper.InternalStorage.writeObject(any(File.class), eq(data));
/* We can't do it twice in the same process. */
data = new byte[] { 'e' };
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic(never());
StorageHelper.InternalStorage.writeObject(any(File.class), eq(data));
}
use of com.microsoft.appcenter.ingestion.models.json.LogSerializer in project mobile-center-sdk-android by Microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashWithJavaThrowable.
@Test
public void saveWrapperSdkCrashWithJavaThrowable() throws JSONException, IOException {
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
byte[] data = new byte[] { 'd' };
Throwable throwable = new Throwable();
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), throwable, new Exception(), data);
verifyStatic();
StorageHelper.InternalStorage.writeObject(any(File.class), eq(data));
verifyStatic();
StorageHelper.InternalStorage.writeObject(any(File.class), eq(throwable));
/* We can't do it twice in the same process. */
data = new byte[] { 'e' };
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), throwable, new Exception(), data);
verifyStatic(never());
StorageHelper.InternalStorage.writeObject(any(File.class), eq(data));
verifyStatic();
StorageHelper.InternalStorage.writeObject(any(File.class), eq(throwable));
}
use of com.microsoft.appcenter.ingestion.models.json.LogSerializer in project mobile-center-sdk-android by Microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsWithIOExceptionAfterLog.
@Test
public void saveWrapperSdkCrashFailsWithIOExceptionAfterLog() throws IOException, JSONException {
byte[] data = { 'd' };
doThrow(new IOException()).when(StorageHelper.InternalStorage.class);
StorageHelper.InternalStorage.writeObject(any(File.class), eq(data));
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic();
AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {
@Override
public boolean matches(Object argument) {
return argument instanceof IOException;
}
}));
/* Second call is ignored. */
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), new byte[] { 'e' });
/* No more error. */
verifyStatic();
AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {
@Override
public boolean matches(Object argument) {
return argument instanceof IOException;
}
}));
}
use of com.microsoft.appcenter.ingestion.models.json.LogSerializer in project mobile-center-sdk-android by Microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashWithOnlyJavaThrowable.
@Test
public void saveWrapperSdkCrashWithOnlyJavaThrowable() throws JSONException, IOException {
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
Throwable throwable = new Throwable();
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), throwable, new Exception(), null);
verifyStatic(never());
StorageHelper.InternalStorage.writeObject(any(File.class), isNull(byte[].class));
verifyStatic();
StorageHelper.InternalStorage.writeObject(any(File.class), eq(throwable));
/* We can't do it twice in the same process. */
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), throwable, new Exception(), null);
verifyStatic();
StorageHelper.InternalStorage.writeObject(any(File.class), eq(throwable));
}
use of com.microsoft.appcenter.ingestion.models.json.LogSerializer in project mobile-center-sdk-android by Microsoft.
the class PushSerializerTest method serialize.
@Test
public void serialize() throws JSONException {
LogContainer expectedContainer = new LogContainer();
List<Log> logs = new ArrayList<>();
{
PushInstallationLog log = new PushInstallationLog();
log.setTimestamp(new Date());
log.setPushToken("TEST");
logs.add(log);
}
expectedContainer.setLogs(logs);
UUID sid = UUIDUtils.randomUUID();
for (Log log : logs) {
log.setSid(sid);
}
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(PushInstallationLog.TYPE, new PushInstallationLogFactory());
String payload = serializer.serializeContainer(expectedContainer);
LogContainer actualContainer = serializer.deserializeContainer(payload);
Assert.assertEquals(expectedContainer, actualContainer);
}
Aggregations