Search in sources :

Example 21 with ErrorReport

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()));
}
Also used : Context(android.content.Context) ErrorReport(com.microsoft.azure.mobile.crashes.model.ErrorReport) ManagedErrorLog(com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog) MobileCenterLog(com.microsoft.azure.mobile.utils.MobileCenterLog) ErrorAttachmentLog(com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog) Log(com.microsoft.azure.mobile.ingestion.models.Log) ManagedErrorLog(com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog) Channel(com.microsoft.azure.mobile.channel.Channel) LogSerializer(com.microsoft.azure.mobile.ingestion.models.json.LogSerializer) UUID(java.util.UUID) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with ErrorReport

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);
}
Also used : Context(android.content.Context) MobileCenterLog(com.microsoft.azure.mobile.utils.MobileCenterLog) ErrorAttachmentLog(com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog) Log(com.microsoft.azure.mobile.ingestion.models.Log) ManagedErrorLog(com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog) Channel(com.microsoft.azure.mobile.channel.Channel) LogSerializer(com.microsoft.azure.mobile.ingestion.models.json.LogSerializer) Matchers.anyString(org.mockito.Matchers.anyString) ErrorReport(com.microsoft.azure.mobile.crashes.model.ErrorReport) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UUID(java.util.UUID) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ErrorReport (com.microsoft.azure.mobile.crashes.model.ErrorReport)22 ManagedErrorLog (com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog)15 File (java.io.File)15 Test (org.junit.Test)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 Channel (com.microsoft.azure.mobile.channel.Channel)12 UUID (java.util.UUID)12 Context (android.content.Context)10 LogSerializer (com.microsoft.azure.mobile.ingestion.models.json.LogSerializer)8 ErrorAttachmentLog (com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog)6 JSONException (org.json.JSONException)6 Log (com.microsoft.azure.mobile.ingestion.models.Log)5 MobileCenterLog (com.microsoft.azure.mobile.utils.MobileCenterLog)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 TestCrashException (com.microsoft.azure.mobile.crashes.model.TestCrashException)4 IOException (java.io.IOException)4 ResultCallback (com.microsoft.azure.mobile.ResultCallback)3 Date (java.util.Date)3 Device (com.microsoft.azure.mobile.ingestion.models.Device)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2