Search in sources :

Example 11 with Exception

use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project mobile-center-sdk-android by Microsoft.

the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsWithIOException.

@Test
public void saveWrapperSdkCrashFailsWithIOException() throws IOException, JSONException {
    doThrow(new IOException()).when(StorageHelper.InternalStorage.class);
    StorageHelper.InternalStorage.write(any(File.class), anyString());
    LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
    when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
    Crashes.getInstance().setLogSerializer(logSerializer);
    WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), new byte[] { 'd' });
    verifyStatic();
    AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof IOException;
        }
    }));
    /* Second call is ignored. */
    WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), new byte[] { 'e' });
    /* No more error. */
    verifyStatic();
    AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof IOException;
        }
    }));
}
Also used : ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) ArgumentMatcher(org.mockito.ArgumentMatcher) StorageHelper(com.microsoft.appcenter.utils.storage.StorageHelper) IOException(java.io.IOException) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) File(java.io.File) Exception(com.microsoft.appcenter.crashes.ingestion.models.Exception) JSONException(org.json.JSONException) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with Exception

use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project mobile-center-sdk-android by Microsoft.

the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsToCreateThrowablePlaceholder.

@Test
public void saveWrapperSdkCrashFailsToCreateThrowablePlaceholder() throws java.lang.Exception {
    LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
    when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
    Crashes.getInstance().setLogSerializer(logSerializer);
    File throwableFile = mock(File.class);
    whenNew(File.class).withParameterTypes(String.class, String.class).withArguments(anyString(), argThat(new ArgumentMatcher<String>() {

        @Override
        public boolean matches(Object argument) {
            return String.valueOf(argument).endsWith(ErrorLogHelper.THROWABLE_FILE_EXTENSION);
        }
    })).thenReturn(throwableFile);
    when(throwableFile.createNewFile()).thenReturn(false);
    byte[] data = new byte[] { 'd' };
    WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
    verifyStatic();
    AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof IOException;
        }
    }));
    /* Second call is ignored. */
    data = new byte[] { 'e' };
    WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
    /* No more error. */
    verifyStatic();
    AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof IOException;
        }
    }));
}
Also used : ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) ArgumentMatcher(org.mockito.ArgumentMatcher) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) Matchers.anyString(org.mockito.Matchers.anyString) IOException(java.io.IOException) File(java.io.File) Exception(com.microsoft.appcenter.crashes.ingestion.models.Exception) JSONException(org.json.JSONException) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Exception (com.microsoft.appcenter.crashes.ingestion.models.Exception)12 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)10 IOException (java.io.IOException)10 Test (org.junit.Test)10 JSONException (org.json.JSONException)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)8 File (java.io.File)7 ArgumentMatcher (org.mockito.ArgumentMatcher)4 TestCrashException (com.microsoft.appcenter.crashes.model.TestCrashException)2 StorageHelper (com.microsoft.appcenter.utils.storage.StorageHelper)2 Date (java.util.Date)2 SuppressLint (android.annotation.SuppressLint)1 ActivityManager (android.app.ActivityManager)1 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)1 Context (android.content.Context)1 Build (android.os.Build)1 NonNull (android.support.annotation.NonNull)1 SessionContext (com.microsoft.appcenter.SessionContext)1 StackFrame (com.microsoft.appcenter.crashes.ingestion.models.StackFrame)1