use of com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method queuePendingCrashesAlwaysSend.
@Test
public void queuePendingCrashesAlwaysSend() throws IOException, ClassNotFoundException, JSONException {
Context mockContext = mock(Context.class);
Channel mockChannel = mock(Channel.class);
ErrorAttachmentLog mockAttachment = mock(ErrorAttachmentLog.class);
when(mockAttachment.getId()).thenReturn(UUID.randomUUID());
when(mockAttachment.getErrorId()).thenReturn(UUID.randomUUID());
when(mockAttachment.getContentType()).thenReturn("");
when(mockAttachment.getFileName()).thenReturn("");
when(mockAttachment.getData()).thenReturn(new byte[0]);
when(mockAttachment.isValid()).thenReturn(true);
List<ErrorAttachmentLog> errorAttachmentLogList = Arrays.asList(mockAttachment, mockAttachment);
ErrorReport report = new ErrorReport();
mockStatic(ErrorLogHelper.class);
when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class) });
when(ErrorLogHelper.getStoredThrowableFile(any(UUID.class))).thenReturn(mock(File.class));
when(ErrorLogHelper.getErrorReportFromErrorLog(any(ManagedErrorLog.class), any(Throwable.class))).thenReturn(report);
when(StorageHelper.InternalStorage.read(any(File.class))).thenReturn("");
when(StorageHelper.InternalStorage.readObject(any(File.class))).thenReturn(new RuntimeException());
when(StorageHelper.PreferencesStorage.getBoolean(eq(Crashes.PREF_KEY_ALWAYS_SEND), anyBoolean())).thenReturn(true);
CrashesListener mockListener = mock(CrashesListener.class);
when(mockListener.shouldProcess(report)).thenReturn(true);
when(mockListener.shouldProcess(report)).thenReturn(true);
when(mockListener.shouldAwaitUserConfirmation()).thenReturn(false);
when(mockListener.getErrorAttachments(report)).thenReturn(errorAttachmentLogList);
Crashes crashes = Crashes.getInstance();
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.deserializeLog(anyString())).thenReturn(mErrorLog);
crashes.setLogSerializer(logSerializer);
crashes.setInstanceListener(mockListener);
crashes.onStarted(mockContext, "", mockChannel);
verify(mockListener).shouldProcess(report);
verify(mockListener, never()).shouldAwaitUserConfirmation();
verify(mockListener).getErrorAttachments(report);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object log) {
return log.equals(mErrorLog);
}
}), eq(crashes.getGroupName()));
verify(mockChannel, times(errorAttachmentLogList.size())).enqueue(mockAttachment, crashes.getGroupName());
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method trackException.
@Test
public void trackException() {
/* Track exception test. */
Crashes crashes = Crashes.getInstance();
Channel mockChannel = mock(Channel.class);
crashes.onStarted(mock(Context.class), "", mockChannel);
Crashes.trackException(EXCEPTION);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof ManagedErrorLog && EXCEPTION.getMessage().equals(((ManagedErrorLog) item).getException().getMessage());
}
}), eq(crashes.getGroupName()));
ManagedErrorLog mockLog = mock(ManagedErrorLog.class);
when(mockLog.getFatal()).thenReturn(false);
CrashesListener mockListener = mock(CrashesListener.class);
crashes.setInstanceListener(mockListener);
/* Crashes callback test for trackException. */
crashes.getChannelListener().onBeforeSending(mockLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
crashes.getChannelListener().onSuccess(mockLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
crashes.getChannelListener().onFailure(mockLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
ErrorAttachmentLog attachmentLog = mock(ErrorAttachmentLog.class);
crashes.getChannelListener().onBeforeSending(attachmentLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
crashes.getChannelListener().onSuccess(attachmentLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
crashes.getChannelListener().onFailure(attachmentLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
}
Aggregations