use of com.microsoft.azure.mobile.channel.Channel 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