use of com.microsoft.azure.mobile.crashes.model.TestCrashException in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method getErrorReportFromErrorLog.
@Test
public void getErrorReportFromErrorLog() throws DeviceInfoHelper.DeviceInfoException {
/* Mock base. */
Context mockContext = mock(Context.class);
when(SystemClock.elapsedRealtime()).thenReturn(1000L);
when(Process.myPid()).thenReturn(123);
/* Mock device. */
Device mockDevice = mock(Device.class);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mockDevice);
/* Mock process name. */
ActivityManager activityManager = mock(ActivityManager.class);
RunningAppProcessInfo runningAppProcessInfo = new RunningAppProcessInfo(null, 0, null);
runningAppProcessInfo.pid = 123;
runningAppProcessInfo.processName = "right.process";
when(mockContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(activityManager);
when(activityManager.getRunningAppProcesses()).thenReturn(Arrays.asList(mock(RunningAppProcessInfo.class), runningAppProcessInfo));
/* Mock architecture. */
Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", 23);
Whitebox.setInternalState(Build.class, "SUPPORTED_ABIS", new String[] { "armeabi-v7a", "arm" });
/* Create an error log. */
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mockContext, java.lang.Thread.currentThread(), new RuntimeException(new TestCrashException()), java.lang.Thread.getAllStackTraces(), 900, true);
assertNotNull(errorLog);
/* Test. */
Throwable throwable = new RuntimeException();
ErrorReport report = ErrorLogHelper.getErrorReportFromErrorLog(errorLog, throwable);
assertNotNull(report);
assertEquals(errorLog.getId().toString(), report.getId());
assertEquals(errorLog.getErrorThreadName(), report.getThreadName());
assertEquals(throwable, report.getThrowable());
assertEquals(errorLog.getToffset() - errorLog.getAppLaunchTOffset(), report.getAppStartTime().getTime());
assertEquals(errorLog.getToffset(), report.getAppErrorTime().getTime());
assertEquals(errorLog.getDevice(), report.getDevice());
}
use of com.microsoft.azure.mobile.crashes.model.TestCrashException in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method createErrorLog.
@Test
public void createErrorLog() throws DeviceInfoHelper.DeviceInfoException {
/* Dummy coverage of utils class. */
new ErrorLogHelper();
/* Mock base. */
Context mockContext = mock(Context.class);
when(SystemClock.elapsedRealtime()).thenReturn(1000L);
when(Process.myPid()).thenReturn(123);
/* Mock device. */
Device mockDevice = mock(Device.class);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mockDevice);
/* Mock process name. */
ActivityManager activityManager = mock(ActivityManager.class);
RunningAppProcessInfo runningAppProcessInfo = new RunningAppProcessInfo(null, 0, null);
runningAppProcessInfo.pid = 123;
runningAppProcessInfo.processName = "right.process";
when(mockContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(activityManager);
when(activityManager.getRunningAppProcesses()).thenReturn(Arrays.asList(mock(RunningAppProcessInfo.class), runningAppProcessInfo));
/* Mock architecture. */
Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", 23);
Whitebox.setInternalState(Build.class, "SUPPORTED_ABIS", new String[] { "armeabi-v7a", "arm" });
/* Test. */
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mockContext, java.lang.Thread.currentThread(), new RuntimeException(new IOException(new TestCrashException())), java.lang.Thread.getAllStackTraces(), 900, true);
assertNotNull(errorLog);
assertNotNull(errorLog.getId());
assertTrue(System.currentTimeMillis() - errorLog.getToffset() <= 1000);
assertEquals(mockDevice, errorLog.getDevice());
assertEquals(Integer.valueOf(123), errorLog.getProcessId());
assertEquals("right.process", errorLog.getProcessName());
assertNull(errorLog.getParentProcessId());
assertNull(errorLog.getParentProcessName());
assertEquals("armeabi-v7a", errorLog.getArchitecture());
assertEquals((Long) java.lang.Thread.currentThread().getId(), errorLog.getErrorThreadId());
assertEquals(java.lang.Thread.currentThread().getName(), errorLog.getErrorThreadName());
assertEquals(Boolean.TRUE, errorLog.getFatal());
assertEquals(Long.valueOf(100), errorLog.getAppLaunchTOffset());
/* Check first exception. */
Exception topException = errorLog.getException();
sanityCheck(topException);
assertEquals(RuntimeException.class.getName(), topException.getType());
assertNotNull(topException.getMessage());
assertNotNull(topException.getInnerExceptions());
assertEquals(1, topException.getInnerExceptions().size());
/* Check second exception. */
Exception middleException = topException.getInnerExceptions().get(0);
sanityCheck(middleException);
assertEquals(IOException.class.getName(), middleException.getType());
assertNotNull(middleException.getInnerExceptions());
assertEquals(1, middleException.getInnerExceptions().size());
/* Check third exception. */
Exception rootCauseException = middleException.getInnerExceptions().get(0);
sanityCheck(rootCauseException);
assertEquals(TestCrashException.class.getName(), rootCauseException.getType());
assertNotNull(rootCauseException.getMessage());
assertNull(rootCauseException.getInnerExceptions());
/* Check threads. */
assertNotNull(errorLog.getThreads());
assertEquals(java.lang.Thread.getAllStackTraces().size(), errorLog.getThreads().size());
for (Thread thread : errorLog.getThreads()) {
assertNotNull(thread);
assertTrue(thread.getId() > 0);
assertNotNull(thread.getName());
assertNotNull(thread.getFrames());
for (StackFrame frame : thread.getFrames()) {
assertNotNull(frame);
assertNotNull(frame.getClassName());
assertNotNull(frame.getMethodName());
}
}
}
use of com.microsoft.azure.mobile.crashes.model.TestCrashException in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method setWrapperSdkListener.
@Test
public void setWrapperSdkListener() {
mockStatic(ErrorLogHelper.class);
ManagedErrorLog errorLog = new ManagedErrorLog();
errorLog.setId(UUIDUtils.randomUUID());
when(ErrorLogHelper.createErrorLog(any(Context.class), any(Thread.class), any(Throwable.class), anyMapOf(Thread.class, StackTraceElement[].class), anyLong(), anyBoolean())).thenReturn(errorLog);
Crashes.getInstance().setLogSerializer(mock(LogSerializer.class));
Crashes.WrapperSdkListener wrapperSdkListener = mock(Crashes.WrapperSdkListener.class);
Crashes.getInstance().setWrapperSdkListener(wrapperSdkListener);
Crashes.getInstance().saveUncaughtException(Thread.currentThread(), new TestCrashException());
verify(wrapperSdkListener).onCrashCaptured(errorLog);
}
Aggregations