use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AbstractAppCenterServiceTest method onChannelReadyDisabledThenEnable.
@Test
public void onChannelReadyDisabledThenEnable() {
Channel channel = mock(Channel.class);
mService.onStarted(mock(Context.class), "", channel);
verify(channel).removeGroup(mService.getGroupName());
verify(channel).addGroup(eq(mService.getGroupName()), anyInt(), anyLong(), anyInt(), any(Channel.GroupListener.class));
mService.setInstanceEnabled(false);
verify(channel, times(2)).removeGroup(mService.getGroupName());
verify(channel).clear(mService.getGroupName());
verifyNoMoreInteractions(channel);
assertSame(channel, mService.mChannel);
mService.setInstanceEnabled(true);
verify(channel, times(2)).addGroup(mService.getGroupName(), mService.getTriggerCount(), mService.getTriggerInterval(), mService.getTriggerMaxParallelRequests(), mService.getChannelListener());
verifyNoMoreInteractions(channel);
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AbstractAppCenterServiceTest method optionalGroup.
@Test
public void optionalGroup() {
mService = new AbstractAppCenterService() {
@Override
protected String getGroupName() {
return null;
}
@Override
public String getServiceName() {
return "Test";
}
@Override
protected String getLoggerTag() {
return "TestLog";
}
};
Channel channel = mock(Channel.class);
mService.onStarted(mock(Context.class), "", channel);
mService.setInstanceEnabled(false);
mService.setInstanceEnabled(true);
verifyZeroInteractions(channel);
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method setEnabled.
@Test
public void setEnabled() throws InterruptedException {
/* Before start it does not work to change state, it's disabled. */
Analytics analytics = Analytics.getInstance();
Analytics.setEnabled(true);
assertFalse(Analytics.isEnabled().get());
Analytics.setEnabled(false);
assertFalse(Analytics.isEnabled().get());
/* Start. */
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), "", channel);
verify(channel).removeGroup(eq(analytics.getGroupName()));
verify(channel).addGroup(eq(analytics.getGroupName()), anyInt(), anyLong(), anyInt(), any(Channel.GroupListener.class));
verify(channel).addListener(any(Channel.Listener.class));
/* Now we can see the service enabled. */
assertTrue(Analytics.isEnabled().get());
/* Disable. Testing to wait setEnabled to finish while we are at it. */
Analytics.setEnabled(false).get();
assertFalse(Analytics.isEnabled().get());
verify(channel).removeListener(any(SessionTracker.class));
verify(channel, times(2)).removeGroup(analytics.getGroupName());
verify(channel).clear(analytics.getGroupName());
verifyStatic();
StorageHelper.PreferencesStorage.remove("sessions");
Analytics.trackEvent("test");
Analytics.trackPage("test");
analytics.onActivityResumed(new Activity());
analytics.onActivityPaused(new Activity());
verify(channel, never()).enqueue(any(Log.class), eq(analytics.getGroupName()));
/* Enable again, verify the async behavior of setEnabled with the callback. */
final CountDownLatch latch = new CountDownLatch(1);
Analytics.setEnabled(true).thenAccept(new AppCenterConsumer<Void>() {
@Override
public void accept(Void aVoid) {
latch.countDown();
}
});
assertTrue(latch.await(0, TimeUnit.MILLISECONDS));
assertTrue(Analytics.isEnabled().get());
/* Test double call to setEnabled true. */
Analytics.setEnabled(true);
assertTrue(Analytics.isEnabled().get());
Analytics.trackEvent("test");
Analytics.trackPage("test");
verify(channel, times(2)).enqueue(any(Log.class), eq(analytics.getGroupName()));
/* Disable again. */
Analytics.setEnabled(false);
assertFalse(Analytics.isEnabled().get());
Analytics.trackEvent("test");
Analytics.trackPage("test");
analytics.onActivityResumed(new Activity());
analytics.onActivityPaused(new Activity());
/* No more log enqueued. */
verify(channel, times(2)).enqueue(any(Log.class), eq(analytics.getGroupName()));
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method disableAutomaticPageTracking.
@Test
public void disableAutomaticPageTracking() {
Analytics analytics = Analytics.getInstance();
assertTrue(Analytics.isAutoPageTrackingEnabled());
Analytics.setAutoPageTrackingEnabled(false);
assertFalse(Analytics.isAutoPageTrackingEnabled());
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), "", channel);
analytics.onActivityResumed(new MyActivity());
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
return argument instanceof StartSessionLog;
}
}), anyString());
verify(channel, never()).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
return argument instanceof PageLog;
}
}), anyString());
Analytics.setAutoPageTrackingEnabled(true);
assertTrue(Analytics.isAutoPageTrackingEnabled());
analytics.onActivityResumed(new SomeScreen());
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return "SomeScreen".equals(pageLog.getName());
}
return false;
}
}), eq(analytics.getGroupName()));
}
use of com.microsoft.appcenter.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method startSessionAfterUserApproval.
@Test
public void startSessionAfterUserApproval() {
/*
* Disable analytics while in background to set up the initial condition
* simulating the opt-in use case.
*/
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), "", channel);
Analytics.setEnabled(false);
/* App in foreground: no log yet, we are disabled. */
analytics.onActivityResumed(new Activity());
verify(channel, never()).enqueue(any(Log.class), eq(analytics.getGroupName()));
/* Enable: start session sent retroactively. */
Analytics.setEnabled(true);
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
return argument instanceof StartSessionLog;
}
}), eq(analytics.getGroupName()));
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
return argument instanceof PageLog;
}
}), eq(analytics.getGroupName()));
/* Go background. */
analytics.onActivityPaused(new Activity());
/* Disable/enable: nothing happens on background. */
Analytics.setEnabled(false);
Analytics.setEnabled(true);
/* No additional log. */
verify(channel, times(2)).enqueue(any(Log.class), eq(analytics.getGroupName()));
}
Aggregations