use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class CrashesAndroidTest method startFresh.
private void startFresh(CrashesListener listener) throws Exception {
/* Configure new instance. */
AppCenterPrivateHelper.unsetInstance();
Crashes.unsetInstance();
AppCenter.setLogLevel(android.util.Log.VERBOSE);
AppCenter.configure(sApplication, "a");
/* Clean logs. */
AppCenter.setEnabled(false);
AppCenter.setEnabled(true).get();
/* Replace channel. */
Method method = AppCenter.class.getDeclaredMethod("getInstance");
method.setAccessible(true);
AppCenter appCenter = (AppCenter) method.invoke(null);
method = AppCenter.class.getDeclaredMethod("setChannel", Channel.class);
method.setAccessible(true);
method.invoke(appCenter, mChannel);
/* Set listener. */
Crashes.setListener(listener);
/* Start crashes. */
AppCenter.start(Crashes.class);
/* Wait for start. */
assertTrue(Crashes.isEnabled().get());
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class WrapperSdkExceptionManagerAndroidTest method startFresh.
private void startFresh() throws java.lang.Exception {
/* Configure new instance. */
AppCenterPrivateHelper.unsetInstance();
Crashes.unsetInstance();
AppCenter.setLogLevel(android.util.Log.VERBOSE);
AppCenter.configure(sApplication, "a");
/* Replace channel. */
Method method = AppCenter.class.getDeclaredMethod("getInstance");
method.setAccessible(true);
AppCenter appCenter = (AppCenter) method.invoke(null);
method = AppCenter.class.getDeclaredMethod("setChannel", Channel.class);
method.setAccessible(true);
method.invoke(appCenter, mock(Channel.class));
/* Start crashes. */
AppCenter.start(Crashes.class);
/* Wait for start. */
Assert.assertTrue(Crashes.isEnabled().get());
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method queuePendingCrashesShouldProcess.
@Test
public void queuePendingCrashesShouldProcess() throws IOException, ClassNotFoundException, JSONException {
/* Setup mock. */
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.getNewMinidumpFiles()).thenReturn(new File[0]);
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());
CrashesListener mockListener = mock(CrashesListener.class);
when(mockListener.shouldProcess(report)).thenReturn(true);
when(mockListener.shouldAwaitUserConfirmation()).thenReturn(false);
ErrorAttachmentLog mockAttachment = mock(ErrorAttachmentLog.class);
when(mockAttachment.getId()).thenReturn(UUID.randomUUID());
when(mockAttachment.getErrorId()).thenReturn(UUID.randomUUID());
when(mockAttachment.getContentType()).thenReturn("");
when(mockAttachment.getFileName()).thenReturn("");
when(mockAttachment.getData()).thenReturn(new byte[0]);
when(mockAttachment.isValid()).thenReturn(true);
ErrorAttachmentLog mockEmptyAttachment = mock(ErrorAttachmentLog.class);
final int skipAttachmentLogsCount = 2;
List<ErrorAttachmentLog> errorAttachmentLogList = Arrays.asList(mockAttachment, mockAttachment, mockEmptyAttachment, null);
when(mockListener.getErrorAttachments(report)).thenReturn(errorAttachmentLogList);
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.deserializeLog(anyString())).thenReturn(mErrorLog);
Crashes crashes = Crashes.getInstance();
crashes.setLogSerializer(logSerializer);
crashes.setInstanceListener(mockListener);
crashes.onStarting(mAppCenterHandler);
crashes.onStarted(mockContext, "", mockChannel);
/* Test. */
verify(mockListener).shouldProcess(report);
verify(mockListener).shouldAwaitUserConfirmation();
verify(mockListener).getErrorAttachments(report);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object log) {
return log.equals(mErrorLog);
}
}), eq(crashes.getGroupName()));
verify(mockChannel, times(errorAttachmentLogList.size() - skipAttachmentLogsCount)).enqueue(mockAttachment, crashes.getGroupName());
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method noQueueNullLog.
@Test
public void noQueueNullLog() throws JSONException {
Context mockContext = mock(Context.class);
Channel mockChannel = mock(Channel.class);
mockStatic(ErrorLogHelper.class);
when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class) });
when(ErrorLogHelper.getNewMinidumpFiles()).thenReturn(new File[0]);
Crashes crashes = Crashes.getInstance();
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.deserializeLog(anyString())).thenReturn(null);
crashes.setLogSerializer(logSerializer);
crashes.onStarting(mAppCenterHandler);
crashes.onStarted(mockContext, "", mockChannel);
verify(mockChannel, never()).enqueue(any(Log.class), anyString());
}
use of com.microsoft.appcenter.channel.Channel 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.getNewMinidumpFiles()).thenReturn(new File[0]);
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.onStarting(mAppCenterHandler);
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()));
}
Aggregations