use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method processPendingErrorsCorrupted.
@Test
public void processPendingErrorsCorrupted() throws JSONException {
mockStatic(ErrorLogHelper.class);
when(ErrorLogHelper.getStoredErrorLogFiles()).thenReturn(new File[] { mock(File.class) });
when(ErrorLogHelper.getNewMinidumpFiles()).thenReturn(new File[0]);
when(StorageHelper.InternalStorage.read(any(File.class))).thenReturn("");
Crashes crashes = Crashes.getInstance();
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.deserializeLog(anyString())).thenReturn(mock(ManagedErrorLog.class));
crashes.setLogSerializer(logSerializer);
CrashesListener listener = mock(CrashesListener.class);
crashes.setInstanceListener(listener);
Channel channel = mock(Channel.class);
crashes.onStarting(mAppCenterHandler);
crashes.onStarted(mock(Context.class), "", channel);
verifyZeroInteractions(listener);
verify(channel, 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 noQueueingWhenDisabled.
@Test
public void noQueueingWhenDisabled() {
mockStatic(ErrorLogHelper.class);
when(ErrorLogHelper.getErrorStorageDirectory()).thenReturn(errorStorageDirectory.getRoot());
when(StorageHelper.PreferencesStorage.getBoolean(CRASHES_ENABLED_KEY, true)).thenReturn(false);
Channel channel = mock(Channel.class);
Crashes crashes = Crashes.getInstance();
crashes.onStarting(mAppCenterHandler);
crashes.onStarted(mock(Context.class), "", channel);
verify(channel, never()).enqueue(any(Log.class), anyString());
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class PushTest method setEnabled.
@Test
public void setEnabled() throws InterruptedException, FirebaseUtils.FirebaseUnavailableException {
/* Before start it's disabled. */
assertFalse(Push.isEnabled().get());
verifyStatic();
AppCenterLog.error(anyString(), anyString());
/* Start. */
String testToken = "TEST";
Push push = Push.getInstance();
Channel channel = mock(Channel.class);
when(mFirebaseInstanceId.getToken()).thenReturn(testToken);
start(mock(Context.class), push, channel);
verify(channel).removeGroup(eq(push.getGroupName()));
assertTrue(Push.isEnabled().get());
verify(mFirebaseInstanceId).getToken();
verify(channel).enqueue(any(PushInstallationLog.class), eq(push.getGroupName()));
/* Enable while already enabled. */
Push.setEnabled(true);
assertTrue(Push.isEnabled().get());
/* Verify behavior happened only once. */
verify(mFirebaseInstanceId).getToken();
verify(channel).enqueue(any(PushInstallationLog.class), eq(push.getGroupName()));
/* Disable. */
Push.setEnabled(false).get();
assertFalse(Push.isEnabled().get());
verify(channel).clear(push.getGroupName());
verify(channel, times(2)).removeGroup(eq(push.getGroupName()));
/* Disable again. Test waiting with async callback. */
final CountDownLatch latch = new CountDownLatch(1);
Push.setEnabled(false).thenAccept(new AppCenterConsumer<Void>() {
@Override
public void accept(Void aVoid) {
latch.countDown();
}
});
assertTrue(latch.await(0, TimeUnit.MILLISECONDS));
/* Ignore on token refresh. */
push.onTokenRefresh(testToken);
/* Verify behavior happened only once. */
verify(mFirebaseInstanceId).getToken();
verify(channel).enqueue(any(PushInstallationLog.class), eq(push.getGroupName()));
/* Make sure no logging when posting check activity intent commands. */
Activity activity = mock(Activity.class);
when(activity.getIntent()).thenReturn(mock(Intent.class));
push.onActivityResumed(activity);
/* No additional error was logged since before start. */
verifyStatic();
AppCenterLog.error(anyString(), anyString());
verify(mFirebaseAnalyticsInstance).setAnalyticsCollectionEnabled(false);
verify(mFirebaseAnalyticsInstance, never()).setAnalyticsCollectionEnabled(true);
/* If disabled before start, still we must disable firebase. */
Push.unsetInstance();
push = Push.getInstance();
start(mock(Context.class), push, channel);
verify(mFirebaseAnalyticsInstance, times(2)).setAnalyticsCollectionEnabled(false);
verify(mFirebaseAnalyticsInstance, never()).setAnalyticsCollectionEnabled(true);
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class PushTest method receivedInForeground.
@Test
public void receivedInForeground() {
PushListener pushListener = mock(PushListener.class);
Push.setListener(pushListener);
Context contextMock = mock(Context.class);
Push push = Push.getInstance();
Channel channel = mock(Channel.class);
start(contextMock, push, channel);
Activity activity = mock(Activity.class);
when(activity.getIntent()).thenReturn(mock(Intent.class));
push.onActivityResumed(activity);
/* Mock some message. */
Intent pushIntent = createPushIntent("some title", "some message", null);
Push.getInstance().onMessageReceived(contextMock, pushIntent);
ArgumentCaptor<PushNotification> captor = ArgumentCaptor.forClass(PushNotification.class);
verify(pushListener).onPushNotificationReceived(eq(activity), captor.capture());
PushNotification pushNotification = captor.getValue();
assertNotNull(pushNotification);
assertEquals("some title", pushNotification.getTitle());
assertEquals("some message", pushNotification.getMessage());
assertEquals(new HashMap<String, String>(), pushNotification.getCustomData());
/* If disabled, no notification anymore. */
Push.setEnabled(false);
Push.getInstance().onMessageReceived(contextMock, pushIntent);
/* Called once. */
verify(pushListener).onPushNotificationReceived(eq(activity), captor.capture());
/* Enabled but remove listener. */
Push.setEnabled(true);
Push.setListener(null);
Push.getInstance().onMessageReceived(contextMock, pushIntent);
/* Called once. */
verify(pushListener).onPushNotificationReceived(eq(activity), captor.capture());
/* Mock notification and custom data. */
Push.setListener(pushListener);
Map<String, String> data = new HashMap<>();
data.put("a", "b");
data.put("c", "d");
pushIntent = createPushIntent("some title", "some message", data);
Push.getInstance().onMessageReceived(contextMock, pushIntent);
verify(pushListener, times(2)).onPushNotificationReceived(eq(activity), captor.capture());
pushNotification = captor.getValue();
assertNotNull(pushNotification);
assertEquals(data, pushNotification.getCustomData());
/* Disable while posting the command to the U.I. thread. */
activity = mock(Activity.class);
when(activity.getIntent()).thenReturn(mock(Intent.class));
push.onActivityResumed(activity);
final AtomicReference<Runnable> runnable = new AtomicReference<>();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
runnable.set((Runnable) invocation.getArguments()[0]);
return null;
}
}).when(HandlerUtils.class);
HandlerUtils.runOnUiThread(any(Runnable.class));
Push.getInstance().onMessageReceived(contextMock, pushIntent);
Push.setEnabled(false);
runnable.get().run();
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
/* Remove listener while posting to UI thread. */
Push.setEnabled(true);
Push.getInstance().onMessageReceived(contextMock, pushIntent);
Push.setListener(null);
runnable.get().run();
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
/* Update listener while posting to UI thread. */
Push.setListener(pushListener);
Push.getInstance().onMessageReceived(contextMock, pushIntent);
PushListener pushListener2 = mock(PushListener.class);
Push.setListener(pushListener2);
runnable.get().run();
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
verify(pushListener2).onPushNotificationReceived(eq(activity), captor.capture());
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class PushTest method verifyEnableFirebaseAnalyticsBeforeStart.
@SuppressWarnings("deprecation")
@Test
public void verifyEnableFirebaseAnalyticsBeforeStart() throws FirebaseUtils.FirebaseUnavailableException {
Context contextMock = mock(Context.class);
Push push = Push.getInstance();
Channel channel = mock(Channel.class);
Push.enableFirebaseAnalytics(contextMock);
start(contextMock, push, channel);
verify(mFirebaseAnalyticsInstance, never()).setAnalyticsCollectionEnabled(false);
}
Aggregations