use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project mobile-center-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 mobile-center-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 mobile-center-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 mobile-center-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 mobile-center-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());
}
Aggregations