use of com.microsoft.azure.mobile.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method buildErrorReportError.
@Test
public void buildErrorReportError() throws IOException, ClassNotFoundException {
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(null);
Exception classNotFoundException = mock(ClassNotFoundException.class);
Exception ioException = mock(IOException.class);
when(StorageHelper.InternalStorage.readObject(any(File.class))).thenThrow(classNotFoundException).thenThrow(ioException);
Crashes crashes = Crashes.getInstance();
ErrorReport report = crashes.buildErrorReport(mErrorLog);
assertNull(report);
report = crashes.buildErrorReport(mErrorLog);
assertNull(report);
verifyStatic();
MobileCenterLog.error(eq(Crashes.LOG_TAG), anyString(), eq(classNotFoundException));
verifyStatic();
MobileCenterLog.error(eq(Crashes.LOG_TAG), anyString(), eq(ioException));
}
use of com.microsoft.azure.mobile.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelper method getErrorReportFromErrorLog.
@NonNull
public static ErrorReport getErrorReportFromErrorLog(@NonNull ManagedErrorLog log, Throwable throwable) {
ErrorReport report = new ErrorReport();
report.setId(log.getId().toString());
report.setThreadName(log.getErrorThreadName());
report.setThrowable(throwable);
report.setAppStartTime(new Date(log.getToffset() - log.getAppLaunchTOffset()));
report.setAppErrorTime(new Date(log.getToffset()));
report.setDevice(log.getDevice());
return report;
}
use of com.microsoft.azure.mobile.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method handleUserConfirmationDoNotSend.
@Test
public void handleUserConfirmationDoNotSend() throws IOException, ClassNotFoundException, JSONException {
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(new ErrorReport());
when(StorageHelper.InternalStorage.read(any(File.class))).thenReturn("");
when(StorageHelper.InternalStorage.readObject(any(File.class))).thenReturn(null);
CrashesListener mockListener = mock(CrashesListener.class);
when(mockListener.shouldProcess(any(ErrorReport.class))).thenReturn(true);
when(mockListener.shouldAwaitUserConfirmation()).thenReturn(true);
Crashes crashes = Crashes.getInstance();
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.deserializeLog(anyString())).thenReturn(mErrorLog);
crashes.setLogSerializer(logSerializer);
crashes.setInstanceListener(mockListener);
crashes.onStarted(mock(Context.class), "", mock(Channel.class));
Crashes.notifyUserConfirmation(Crashes.DONT_SEND);
verify(mockListener, never()).getErrorAttachments(any(ErrorReport.class));
verify(mMockLooper).quit();
verifyStatic();
ErrorLogHelper.removeStoredErrorLogFile(mErrorLog.getId());
verifyStatic();
ErrorLogHelper.removeStoredThrowableFile(mErrorLog.getId());
}
use of com.microsoft.azure.mobile.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method crashInLastSessionError.
@Test
public void crashInLastSessionError() throws JSONException, IOException, ClassNotFoundException {
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.deserializeLog(anyString())).thenReturn(mock(ManagedErrorLog.class));
mockStatic(ErrorLogHelper.class);
File lastErrorLogFile = errorStorageDirectory.newFile("last-error-log.json");
when(ErrorLogHelper.getLastErrorLogFile()).thenReturn(lastErrorLogFile);
when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { lastErrorLogFile });
when(StorageHelper.InternalStorage.read(any(File.class))).thenReturn("");
Crashes.getInstance().setLogSerializer(logSerializer);
assertFalse(Crashes.hasCrashedInLastSession());
JSONException jsonException = new JSONException("Fake JSON exception");
when(logSerializer.deserializeLog(anyString())).thenThrow(jsonException);
ResultCallback<ErrorReport> callback = new ResultCallback<ErrorReport>() {
@Override
public void onResult(ErrorReport data) {
assertNull(data);
}
};
/*
* Last session error is only fetched upon initialization: enabled and channel ready.
* Here the service is enabled by default but we are waiting channel to be ready, simulate that.
*/
assertTrue(Crashes.isEnabled());
Crashes.getLastSessionCrashReport(callback);
Crashes.getInstance().onStarted(mock(Context.class), "", mock(Channel.class));
assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReport(callback);
/*
* De-serializing fails twice: processing the log from last time as part of the bulk processing.
* And loading that same file for exposing it in getLastErrorReport.
*/
verifyStatic(times(2));
MobileCenterLog.error(eq(Crashes.LOG_TAG), anyString(), eq(jsonException));
}
use of com.microsoft.azure.mobile.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method getChannelListener.
@Test
public void getChannelListener() throws IOException, ClassNotFoundException {
ErrorReport errorReport = ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, EXCEPTION);
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(mErrorLog, EXCEPTION)).thenReturn(errorReport);
when(StorageHelper.InternalStorage.readObject(any(File.class))).thenReturn(EXCEPTION);
Crashes.setListener(new AbstractCrashesListener() {
@Override
public void onBeforeSending(ErrorReport report) {
assertErrorEquals(mErrorLog, report);
}
@Override
public void onSendingSucceeded(ErrorReport report) {
assertErrorEquals(mErrorLog, report);
}
@Override
public void onSendingFailed(ErrorReport report, Exception e) {
assertErrorEquals(mErrorLog, report);
}
});
Channel.GroupListener listener = Crashes.getInstance().getChannelListener();
listener.onBeforeSending(mErrorLog);
listener.onSuccess(mErrorLog);
listener.onFailure(mErrorLog, EXCEPTION);
}
Aggregations