use of com.microsoft.azure.mobile.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method queuePendingCrashesShouldNotProcess.
@Test
public void queuePendingCrashesShouldNotProcess() throws IOException, ClassNotFoundException, JSONException {
Context mockContext = mock(Context.class);
Channel mockChannel = mock(Channel.class);
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()).thenReturn(new byte[] {});
CrashesListener mockListener = mock(CrashesListener.class);
when(mockListener.shouldProcess(report)).thenReturn(false);
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, never()).getErrorAttachments(report);
verify(mockChannel, never()).enqueue(any(Log.class), eq(crashes.getGroupName()));
}
use of com.microsoft.azure.mobile.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method disabledDuringProcessPendingErrors.
@Test
public void disabledDuringProcessPendingErrors() throws IOException, ClassNotFoundException, JSONException {
ErrorReport errorReport = ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, EXCEPTION);
File errorStorageDirectory = mock(File.class);
when(errorStorageDirectory.listFiles()).thenReturn(new File[0]);
CrashesListener listener = mock(CrashesListener.class);
when(listener.shouldProcess(errorReport)).thenReturn(true);
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.deserializeLog(anyString())).thenReturn(mErrorLog);
Channel channel = mock(Channel.class);
mockStatic(ErrorLogHelper.class);
when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class), mock(File.class) }).thenReturn(new File[] { mock(File.class) });
when(ErrorLogHelper.getErrorStorageDirectory()).thenReturn(errorStorageDirectory);
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);
when(StorageHelper.InternalStorage.read(any(File.class))).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
Crashes.setEnabled(false);
return "";
}
});
/* Disabled while Crashes service is processing pending errors. */
Crashes crashes = Crashes.getInstance();
crashes.setLogSerializer(logSerializer);
crashes.setInstanceListener(listener);
crashes.onStarted(mock(Context.class), "", channel);
verify(channel, never()).enqueue(any(Log.class), anyString());
verify(listener).shouldProcess(errorReport);
verifyNoMoreInteractions(listener);
/* Disabled right before handling user confirmation. */
Crashes.unsetInstance();
Crashes.setEnabled(true);
crashes = Crashes.getInstance();
crashes.setLogSerializer(logSerializer);
crashes.setInstanceListener(listener);
crashes.onStarted(mock(Context.class), "", channel);
verify(channel, never()).enqueue(any(Log.class), anyString());
verify(listener, times(2)).shouldProcess(errorReport);
verifyNoMoreInteractions(listener);
}
Aggregations