use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project AppCenter-SDK-Android by Microsoft.
the class HandledErrorTest method trackExceptionWithEverythingFromWrapper.
@Test
public void trackExceptionWithEverythingFromWrapper() {
/* If we start crashes. */
startCrashes();
/* And set a userId. */
UserIdContext.getInstance().setUserId("omega");
/* When we track error. */
ErrorAttachmentLog textAttachment = ErrorAttachmentLog.attachmentWithText("text", null);
ErrorAttachmentLog binaryAttachment = ErrorAttachmentLog.attachmentWithBinary("hello".getBytes(), "hello.so", "application/octet-stream");
HashMap<String, String> properties = new HashMap<String, String>() {
{
put("a", "b");
}
};
Exception modelException = new Exception();
String errorId = WrapperSdkExceptionManager.trackException(modelException, properties, Arrays.asList(textAttachment, binaryAttachment));
assertNotNull(errorId);
/* Then we send the handled error. */
ArgumentCaptor<Log> logs = ArgumentCaptor.forClass(Log.class);
verify(mChannel, times(3)).enqueue(logs.capture(), eq(mCrashes.getGroupName()), eq(DEFAULTS));
assertNotNull(logs.getAllValues());
assertEquals(3, logs.getAllValues().size());
assertTrue(logs.getAllValues().get(0) instanceof HandledErrorLog);
HandledErrorLog handledErrorLog = (HandledErrorLog) logs.getAllValues().get(0);
assertEquals(modelException, handledErrorLog.getException());
assertEquals(properties, handledErrorLog.getProperties());
assertEquals(errorId, String.valueOf(handledErrorLog.getId()));
/* Then the attachments. */
assertSame(textAttachment, logs.getAllValues().get(1));
assertSame(binaryAttachment, logs.getAllValues().get(2));
/* We send userId only in the error log. */
assertEquals("omega", handledErrorLog.getUserId());
assertNull(logs.getAllValues().get(1).getUserId());
assertNull(logs.getAllValues().get(2).getUserId());
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project AppCenter-SDK-Android by Microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsWithJSONException.
@Test
public void saveWrapperSdkCrashFailsWithJSONException() throws JSONException {
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenThrow(new JSONException("mock"));
Crashes.getInstance().setLogSerializer(logSerializer);
String data = "d";
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 JSONException;
}
}));
/* Second call is ignored. */
data = "e";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
/* No more error. */
verifyStatic();
AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {
@Override
public boolean matches(Object argument) {
return argument instanceof JSONException;
}
}));
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project AppCenter-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);
String data = "d";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic();
FileManager.write(any(File.class), eq(data));
/* We can't do it twice in the same process. */
data = "e";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic(never());
FileManager.write(any(File.class), eq(data));
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project AppCenter-SDK-Android by Microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsWithIOExceptionAfterLog.
@Test
public void saveWrapperSdkCrashFailsWithIOExceptionAfterLog() throws IOException, JSONException {
String data = "d";
doThrow(new IOException()).when(FileManager.class);
FileManager.write(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. */
data = "e";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
/* 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.crashes.ingestion.models.Exception in project mobile-center-sdk-android by Microsoft.
the class HandledErrorTest method trackExceptionWithOneAttachmentFromWrapper.
@Test
public void trackExceptionWithOneAttachmentFromWrapper() {
/* If we start crashes. */
startCrashes();
/* When we track error with an attachment. */
ErrorAttachmentLog textAttachment = ErrorAttachmentLog.attachmentWithText("text", null);
Exception exception = new Exception();
String errorId = WrapperSdkExceptionManager.trackException(exception, null, Collections.singleton(textAttachment));
assertNotNull(errorId);
/* Then we send the handled error. */
ArgumentCaptor<Log> log = ArgumentCaptor.forClass(Log.class);
verify(mChannel, times(2)).enqueue(log.capture(), eq(mCrashes.getGroupName()), eq(DEFAULTS));
assertNotNull(log.getAllValues());
assertEquals(2, log.getAllValues().size());
assertTrue(log.getAllValues().get(0) instanceof HandledErrorLog);
HandledErrorLog handledErrorLog = (HandledErrorLog) log.getAllValues().get(0);
assertEquals(exception, handledErrorLog.getException());
assertEquals(errorId, String.valueOf(handledErrorLog.getId()));
/* Then the attachment. */
assertSame(textAttachment, log.getAllValues().get(1));
}
Aggregations