use of com.microsoft.appcenter.SessionContext in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method testNativeCrashLog.
private ManagedErrorLog testNativeCrashLog(long appStartTime, long crashTime, boolean correlateSession) throws Exception {
/* Setup mock for a crash in disk. */
File minidumpFile = mock(File.class);
when(minidumpFile.getName()).thenReturn("mockFile");
when(minidumpFile.lastModified()).thenReturn(crashTime);
mockStatic(SessionContext.class);
SessionContext sessionContext = mock(SessionContext.class);
when(SessionContext.getInstance()).thenReturn(sessionContext);
if (correlateSession) {
SessionContext.SessionInfo sessionInfo = mock(SessionContext.SessionInfo.class);
when(sessionContext.getSessionAt(crashTime)).thenReturn(sessionInfo);
when(sessionInfo.getAppLaunchTimestamp()).thenReturn(appStartTime);
}
mockStatic(DeviceInfoHelper.class);
when(DeviceInfoHelper.getDeviceInfo(any(Context.class))).thenReturn(mock(Device.class));
ErrorReport report = new ErrorReport();
mockStatic(ErrorLogHelper.class);
when(ErrorLogHelper.getLastErrorLogFile()).thenReturn(mock(File.class));
when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class) });
when(ErrorLogHelper.getNewMinidumpFiles()).thenReturn(new File[] { minidumpFile });
File pendingDir = mock(File.class);
Whitebox.setInternalState(pendingDir, "path", "");
when(ErrorLogHelper.getPendingMinidumpDirectory()).thenReturn(pendingDir);
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 NativeException());
LogSerializer logSerializer = mock(LogSerializer.class);
ArgumentCaptor<Log> log = ArgumentCaptor.forClass(Log.class);
when(logSerializer.serializeLog(log.capture())).thenReturn("{}");
when(logSerializer.deserializeLog(anyString())).thenAnswer(new Answer<ManagedErrorLog>() {
@Override
public ManagedErrorLog answer(InvocationOnMock invocation) throws Throwable {
ManagedErrorLog log = mock(ManagedErrorLog.class);
when(log.getId()).thenReturn(UUID.randomUUID());
return log;
}
});
/* Start crashes. */
Crashes crashes = Crashes.getInstance();
crashes.setLogSerializer(logSerializer);
crashes.onStarting(mAppCenterHandler);
crashes.onStarted(mock(Context.class), "", mock(Channel.class));
/* Verify timestamps on the crash log. */
assertTrue(Crashes.hasCrashedInLastSession().get());
assertTrue(log.getValue() instanceof ManagedErrorLog);
return (ManagedErrorLog) log.getValue();
}
use of com.microsoft.appcenter.SessionContext in project mobile-center-sdk-android by Microsoft.
the class DistributeBeforeApiSuccessTest method dontEnqueueDistributionStartSessionLogIfLastSessionIdIsNull.
@Test
public void dontEnqueueDistributionStartSessionLogIfLastSessionIdIsNull() throws Exception {
/* Setup mock. */
mockStatic(SessionContext.class);
SessionContext sessionContext = mock(SessionContext.class);
when(SessionContext.getInstance()).thenReturn(sessionContext);
SessionContext.SessionInfo sessionInfo = mock(SessionContext.SessionInfo.class);
when(sessionContext.getSessionAt(anyLong())).thenReturn(sessionInfo);
when(sessionInfo.getSessionId()).thenReturn(null);
when(PreferencesStorage.getString(PREFERENCE_KEY_REQUEST_ID)).thenReturn("r");
/* Enable in-app updates. */
start();
Distribute.getInstance().storeRedirectionParameters("r", "g", null);
/* Verify the log was sent. */
verify(mChannel, never()).enqueue(any(DistributionStartSessionLog.class), eq(Distribute.getInstance().getGroupName()));
}
use of com.microsoft.appcenter.SessionContext in project mobile-center-sdk-android by Microsoft.
the class DistributeBeforeApiSuccessTest method enqueueDistributionStartSessionLogAfterEnablingUpdates.
@Test
public void enqueueDistributionStartSessionLogAfterEnablingUpdates() throws Exception {
/* Setup mock. */
mockStatic(SessionContext.class);
SessionContext sessionContext = mock(SessionContext.class);
when(SessionContext.getInstance()).thenReturn(sessionContext);
SessionContext.SessionInfo sessionInfo = mock(SessionContext.SessionInfo.class);
when(sessionContext.getSessionAt(anyLong())).thenReturn(sessionInfo);
when(sessionInfo.getSessionId()).thenReturn(UUID.randomUUID());
when(PreferencesStorage.getString(PREFERENCE_KEY_REQUEST_ID)).thenReturn("r");
/* Enable in-app updates. */
start();
Distribute.getInstance().storeRedirectionParameters("r", "g", null);
/* Verify the log was sent. */
verify(mChannel).enqueue(any(DistributionStartSessionLog.class), eq(Distribute.getInstance().getGroupName()));
}
use of com.microsoft.appcenter.SessionContext in project mobile-center-sdk-android by Microsoft.
the class DistributeBeforeApiSuccessTest method dontEnqueueDistributionStartSessionLogIfNoSessionsWereLoggedBefore.
@Test
public void dontEnqueueDistributionStartSessionLogIfNoSessionsWereLoggedBefore() throws Exception {
/* Setup mock. */
mockStatic(SessionContext.class);
SessionContext sessionContext = mock(SessionContext.class);
when(SessionContext.getInstance()).thenReturn(sessionContext);
when(sessionContext.getSessionAt(anyLong())).thenReturn(null);
when(PreferencesStorage.getString(PREFERENCE_KEY_REQUEST_ID)).thenReturn("r");
/* Enable in-app updates. */
start();
Distribute.getInstance().storeRedirectionParameters("r", "g", null);
/* Verify the log was sent. */
verify(mChannel, never()).enqueue(any(DistributionStartSessionLog.class), eq(Distribute.getInstance().getGroupName()));
}
Aggregations