use of com.microsoft.appcenter.utils.async.AppCenterFuture in project mobile-center-sdk-android by Microsoft.
the class UncaughtExceptionHandlerTest method setUp.
@Before
public void setUp() throws java.lang.Exception {
Crashes.unsetInstance();
mockStatic(AppCenter.class);
mockStatic(AppCenterLog.class);
mockStatic(SystemClock.class);
mockStatic(StorageHelper.PreferencesStorage.class);
mockStatic(StorageHelper.InternalStorage.class);
mockStatic(ErrorLogHelper.class);
mockStatic(DeviceInfoHelper.class);
mockStatic(System.class);
@SuppressWarnings("unchecked") AppCenterFuture<Boolean> future = (AppCenterFuture<Boolean>) mock(AppCenterFuture.class);
when(AppCenter.isEnabled()).thenReturn(future);
when(future.get()).thenReturn(true);
when(StorageHelper.PreferencesStorage.getBoolean(CRASHES_ENABLED_KEY, true)).thenReturn(true);
/* Then simulate further changes to state. */
PowerMockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
/* Whenever the new state is persisted, make further calls return the new state. */
boolean enabled = (Boolean) invocation.getArguments()[1];
Mockito.when(StorageHelper.PreferencesStorage.getBoolean(CRASHES_ENABLED_KEY, true)).thenReturn(enabled);
return null;
}
}).when(StorageHelper.PreferencesStorage.class);
StorageHelper.PreferencesStorage.putBoolean(eq(CRASHES_ENABLED_KEY), anyBoolean());
ManagedErrorLog errorLogMock = mock(ManagedErrorLog.class);
when(ErrorLogHelper.getErrorStorageDirectory()).thenReturn(new File("."));
when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[0]);
when(ErrorLogHelper.createErrorLog(any(Context.class), any(Thread.class), any(Exception.class), Matchers.<Map<Thread, StackTraceElement[]>>any(), anyLong(), anyBoolean())).thenReturn(errorLogMock);
when(errorLogMock.getId()).thenReturn(UUID.randomUUID());
mDefaultExceptionHandler = mock(Thread.UncaughtExceptionHandler.class);
Thread.setDefaultUncaughtExceptionHandler(mDefaultExceptionHandler);
mExceptionHandler = new UncaughtExceptionHandler();
/* Mock handlers. */
mockStatic(HandlerUtils.class);
Answer<Void> runNow = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((Runnable) invocation.getArguments()[0]).run();
return null;
}
};
doAnswer(runNow).when(HandlerUtils.class);
HandlerUtils.runOnUiThread(any(Runnable.class));
AppCenterHandler handler = mock(AppCenterHandler.class);
Crashes.getInstance().onStarting(handler);
doAnswer(runNow).when(handler).post(any(Runnable.class), any(Runnable.class));
}
use of com.microsoft.appcenter.utils.async.AppCenterFuture in project mobile-center-sdk-android by Microsoft.
the class WrapperSdkExceptionManagerTest method setUp.
@Before
public void setUp() {
Crashes.unsetInstance();
mockStatic(AppCenter.class);
mockStatic(StorageHelper.PreferencesStorage.class);
mockStatic(StorageHelper.InternalStorage.class);
mockStatic(AppCenterLog.class);
mockStatic(ErrorLogHelper.class);
when(ErrorLogHelper.getErrorStorageDirectory()).thenReturn(errorStorageDirectory.getRoot());
ManagedErrorLog errorLogMock = mock(ManagedErrorLog.class);
when(errorLogMock.getId()).thenReturn(UUID.randomUUID());
when(ErrorLogHelper.createErrorLog(any(Context.class), any(Thread.class), any(Exception.class), Matchers.<Map<Thread, StackTraceElement[]>>any(), anyLong(), anyBoolean())).thenReturn(errorLogMock);
@SuppressWarnings("unchecked") AppCenterFuture<Boolean> future = (AppCenterFuture<Boolean>) mock(AppCenterFuture.class);
when(AppCenter.isEnabled()).thenReturn(future);
when(future.get()).thenReturn(true);
when(StorageHelper.PreferencesStorage.getBoolean(CRASHES_ENABLED_KEY, true)).thenReturn(true);
/* Mock handlers. */
mockStatic(HandlerUtils.class);
Answer<Void> runNow = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((Runnable) invocation.getArguments()[0]).run();
return null;
}
};
doAnswer(runNow).when(HandlerUtils.class);
HandlerUtils.runOnUiThread(any(Runnable.class));
AppCenterHandler handler = mock(AppCenterHandler.class);
Crashes.getInstance().onStarting(handler);
doAnswer(runNow).when(handler).post(any(Runnable.class), any(Runnable.class));
}
Aggregations