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 saveWrapperSdkCrashFailsWithIOException.
@Test
public void saveWrapperSdkCrashFailsWithIOException() throws IOException, JSONException {
doThrow(new IOException()).when(FileManager.class);
FileManager.write(any(File.class), anyString());
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();
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 appcenter-sdk-android by microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperExceptionWhenSDKDisabled.
@Test
public void saveWrapperExceptionWhenSDKDisabled() throws JSONException {
when(SharedPreferencesManager.getBoolean(CRASHES_ENABLED_KEY, true)).thenReturn(false);
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
Crashes.getInstance().setLogSerializer(logSerializer);
String data = "d";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verify(logSerializer, never()).serializeLog(any(Log.class));
verifyNoMoreInteractions(ErrorLogHelper.class);
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsToCreateThrowablePlaceholder.
@Test
public void saveWrapperSdkCrashFailsToCreateThrowablePlaceholder() throws java.lang.Exception {
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
File throwableFile = mock(File.class);
whenNew(File.class).withParameterTypes(String.class, String.class).withArguments(anyString(), argThat(new ArgumentMatcher<String>() {
@Override
public boolean matches(Object argument) {
return String.valueOf(argument).endsWith(ErrorLogHelper.THROWABLE_FILE_EXTENSION);
}
})).thenReturn(throwableFile);
when(throwableFile.createNewFile()).thenReturn(false);
String data = "d";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic(times(3));
AppCenterLog.debug(anyString(), anyString());
/* Second call is ignored. */
data = "e";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
/* No more error. */
verifyStatic(times(3));
AppCenterLog.debug(anyString(), anyString());
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashWithJavaThrowable.
@Test
@PrepareForTest(android.util.Log.class)
public void saveWrapperSdkCrashWithJavaThrowable() throws JSONException, IOException {
String mockData = "mock";
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn(mockData);
Crashes.getInstance().setLogSerializer(logSerializer);
String data = "d";
Throwable throwable = new Throwable();
mockStatic(android.util.Log.class);
Mockito.when(getStackTraceString(any(Throwable.class))).thenReturn(STACK_TRACE);
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), throwable, new Exception(), data);
verifyStatic();
FileManager.write(any(File.class), eq(data));
verifyStatic();
FileManager.write(any(File.class), eq(mockData));
/* We can't do it twice in the same process. */
data = "e";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), throwable, new Exception(), data);
verifyStatic(never());
FileManager.write(any(File.class), eq(data));
verifyStatic();
FileManager.write(any(File.class), eq(mockData));
}
Aggregations