use of com.microsoft.azure.mobile.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method activityResumed.
private void activityResumed(final String expectedName, android.app.Activity activity) {
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarted(mock(Context.class), "", channel);
analytics.onActivityResumed(activity);
analytics.onActivityPaused(activity);
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return expectedName.equals(pageLog.getName());
}
return false;
}
}), eq(analytics.getGroupName()));
}
use of com.microsoft.azure.mobile.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method trackEvent.
@Test
public void trackEvent() {
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarted(mock(Context.class), "", channel);
final String name = "testEvent";
final HashMap<String, String> properties = new HashMap<>();
properties.put("a", "b");
Analytics.trackEvent(name, properties);
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof EventLog) {
EventLog eventLog = (EventLog) item;
return name.equals(eventLog.getName()) && properties.equals(eventLog.getProperties()) && eventLog.getId() != null;
}
return false;
}
}), eq(analytics.getGroupName()));
}
use of com.microsoft.azure.mobile.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.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.azure.mobile.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method setEnabled.
@Test
public void setEnabled() {
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
assertTrue(Analytics.isEnabled());
Analytics.setEnabled(true);
assertTrue(Analytics.isEnabled());
Analytics.setEnabled(false);
assertFalse(Analytics.isEnabled());
analytics.onStarted(mock(Context.class), "", channel);
verify(channel).clear(analytics.getGroupName());
verify(channel).removeGroup(eq(analytics.getGroupName()));
Analytics.trackEvent("test");
Analytics.trackPage("test");
analytics.onActivityResumed(new Activity());
analytics.onActivityPaused(new Activity());
verifyNoMoreInteractions(channel);
/* Enable back, testing double calls. */
Analytics.setEnabled(true);
assertTrue(Analytics.isEnabled());
Analytics.setEnabled(true);
assertTrue(Analytics.isEnabled());
verify(channel).addGroup(eq(analytics.getGroupName()), anyInt(), anyInt(), anyInt(), any(Channel.GroupListener.class));
verify(channel).addListener(any(SessionTracker.class));
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());
/* clear and removeGroup are being called in this test method. */
verify(channel, times(2)).clear(analytics.getGroupName());
verify(channel, times(2)).removeGroup(eq(analytics.getGroupName()));
verify(channel).removeListener(any(SessionTracker.class));
Analytics.trackEvent("test");
Analytics.trackPage("test");
analytics.onActivityResumed(new Activity());
analytics.onActivityPaused(new Activity());
verifyNoMoreInteractions(channel);
/* Verify session state has been cleared. */
verifyStatic();
StorageHelper.PreferencesStorage.remove("sessions");
}
use of com.microsoft.azure.mobile.channel.Channel in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method testTrackPage.
@Test
public void testTrackPage() {
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarted(mock(Context.class), "", channel);
Analytics.trackPage(null, null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage("", null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage(" ", null);
verify(channel, times(1)).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage(generateString(257, '*'), null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage(generateString(256, '*'), null);
verify(channel, times(1)).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage("pageName", new HashMap<String, String>() {
{
put(null, null);
put("", null);
put(generateString(65, '*'), null);
put("1", null);
put("2", generateString(65, '*'));
}
});
verify(channel, times(1)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return pageLog.getProperties().size() == 0;
}
return false;
}
}), anyString());
reset(channel);
final String validMapItem = "valid";
Analytics.trackPage("pageName", new HashMap<String, String>() {
{
for (int i = 0; i < 10; i++) {
put(validMapItem + i, validMapItem);
}
}
});
verify(channel, times(1)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return pageLog.getProperties().size() == 5;
}
return false;
}
}), anyString());
}
Aggregations