use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class PushTest method nullTokenOnStartThenRefresh.
@Test
public void nullTokenOnStartThenRefresh() {
/* Start. */
String testToken = "TEST";
Push push = Push.getInstance();
Channel channel = mock(Channel.class);
start(mock(Context.class), push, channel);
assertTrue(Push.isEnabled().get());
verify(mFirebaseInstanceId).getToken();
verify(channel, never()).enqueue(any(PushInstallationLog.class), eq(push.getGroupName()));
/* Refresh. */
push.onTokenRefresh(testToken);
verify(channel).enqueue(any(PushInstallationLog.class), eq(push.getGroupName()));
/* Only once. */
verify(mFirebaseInstanceId).getToken();
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class PushTest method clickedFromBackgroundDisableWhilePostingToUI.
@Test
public void clickedFromBackgroundDisableWhilePostingToUI() {
/* Mock activity to contain push */
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);
Intent intent = createPushIntent(null, null, null);
when(PushIntentUtils.getGoogleMessageId(intent)).thenReturn("some id");
when(activity.getIntent()).thenReturn(intent);
/* Disable while posting the command to the U.I. thread. */
activity = mock(Activity.class);
when(activity.getIntent()).thenReturn(intent);
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.onActivityResumed(activity);
Push.setEnabled(false);
runnable.get().run();
ArgumentCaptor<PushNotification> captor = ArgumentCaptor.forClass(PushNotification.class);
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class PushTest method verifyEnableFirebaseAnalytics.
@SuppressWarnings("deprecation")
@Test
public void verifyEnableFirebaseAnalytics() throws FirebaseUtils.FirebaseUnavailableException {
Context contextMock = mock(Context.class);
Push push = Push.getInstance();
Channel channel = mock(Channel.class);
start(contextMock, push, channel);
verify(mFirebaseAnalyticsInstance).setAnalyticsCollectionEnabled(false);
Push.enableFirebaseAnalytics(contextMock);
verify(mFirebaseAnalyticsInstance).setAnalyticsCollectionEnabled(false);
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class PushTest method clickedFromBackground.
@Test
public void clickedFromBackground() {
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);
/* Mock activity to contain push */
Activity activity = mock(Activity.class);
Map<String, String> customMap = new HashMap<>();
customMap.put("custom", "data");
customMap.put("b", "c");
Intent intent = createPushIntent(null, null, customMap);
when(PushIntentUtils.getGoogleMessageId(intent)).thenReturn("reserved value by google");
when(activity.getIntent()).thenReturn(intent);
/* Simulate we detect push in onCreate. */
push.onActivityCreated(activity, null);
ArgumentCaptor<PushNotification> captor = ArgumentCaptor.forClass(PushNotification.class);
verify(pushListener).onPushNotificationReceived(eq(activity), captor.capture());
PushNotification pushNotification = captor.getValue();
assertNotNull(pushNotification);
assertNull(pushNotification.getTitle());
assertNull(pushNotification.getMessage());
assertEquals(customMap, pushNotification.getCustomData());
/* On started on resume will not duplicate the callback. */
push.onActivityStarted(activity);
push.onActivityResumed(activity);
verify(pushListener).onPushNotificationReceived(eq(activity), captor.capture());
/* Disable SDK stops callbacks. */
push.onActivityPaused(activity);
activity = mock(Activity.class);
when(activity.getIntent()).thenReturn(intent);
when(PushIntentUtils.getGoogleMessageId(intent)).thenReturn("new id");
Push.setEnabled(false);
push.onActivityResumed(activity);
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
verifyStatic(never());
AppCenterLog.error(anyString(), anyString());
/* Same effect if we disable App Center. */
when(mBooleanAppCenterFuture.get()).thenReturn(false);
push.onActivityResumed(activity);
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
verifyStatic(never());
AppCenterLog.error(anyString(), anyString());
/* Same if we remove listener. */
when(mBooleanAppCenterFuture.get()).thenReturn(true);
Push.setEnabled(true);
Push.setListener(null);
push.onActivityResumed(activity);
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
/* Set listener to read the new push when resumed. */
Push.setListener(pushListener);
push.onActivityResumed(activity);
verify(pushListener).onPushNotificationReceived(eq(activity), captor.capture());
/* If intent extras are null, nothing happens. */
activity = mock(Activity.class);
when(activity.getIntent()).thenReturn(intent);
push.onActivityResumed(activity);
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
/* If intent contains non push extras, same thing. */
when(intent.getExtras()).thenReturn(mock(Bundle.class));
push.onActivityResumed(activity);
verify(pushListener, never()).onPushNotificationReceived(eq(activity), captor.capture());
/* Receiving push with the same id as first push should do nothing. */
when(PushIntentUtils.getGoogleMessageId(intent)).thenReturn("a new id");
push.onActivityResumed(activity);
when(PushIntentUtils.getGoogleMessageId(intent)).thenReturn("reserved value by google");
push.onActivityResumed(activity);
verify(pushListener, times(1)).onPushNotificationReceived(eq(activity), any(PushNotification.class));
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AbstractAppCenterServiceTest method onChannelReadyEnabledThenDisable.
@Test
public void onChannelReadyEnabledThenDisable() {
Channel channel = mock(Channel.class);
mService.onStarted(mock(Context.class), "", channel);
verify(channel).removeGroup(mService.getGroupName());
verify(channel).addGroup(mService.getGroupName(), mService.getTriggerCount(), mService.getTriggerInterval(), mService.getTriggerMaxParallelRequests(), mService.getChannelListener());
verifyNoMoreInteractions(channel);
assertSame(channel, mService.mChannel);
mService.setInstanceEnabled(false);
verify(channel, times(2)).removeGroup(mService.getGroupName());
verify(channel).clear(mService.getGroupName());
verifyNoMoreInteractions(channel);
}
Aggregations