use of com.microsoft.appcenter.analytics.channel.AnalyticsListener in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method analyticsListener.
@Test
public void analyticsListener() throws IOException, ClassNotFoundException {
AnalyticsListener listener = mock(AnalyticsListener.class);
Analytics.setListener(listener);
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), "", channel);
final ArgumentCaptor<Channel.GroupListener> captor = ArgumentCaptor.forClass(Channel.GroupListener.class);
verify(channel).addGroup(anyString(), anyInt(), anyLong(), anyInt(), captor.capture());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
captor.getValue().onBeforeSending((Log) invocation.getArguments()[0]);
captor.getValue().onSuccess((Log) invocation.getArguments()[0]);
captor.getValue().onFailure((Log) invocation.getArguments()[0], new Exception());
return null;
}
}).when(channel).enqueue(any(Log.class), anyString());
Analytics.trackEvent("name");
verify(listener).onBeforeSending(notNull(Log.class));
verify(listener).onSendingSucceeded(notNull(Log.class));
verify(listener).onSendingFailed(notNull(Log.class), notNull(Exception.class));
}
use of com.microsoft.appcenter.analytics.channel.AnalyticsListener in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method testAnalyticsListenerNull.
@Test
public void testAnalyticsListenerNull() {
AnalyticsListener analyticsListener = mock(AnalyticsListener.class);
Analytics.setListener(analyticsListener);
Analytics.setListener(null);
final EventLog testEventLog = new EventLog();
testEventLog.setId(UUID.randomUUID());
testEventLog.setName("name");
final Exception testException = new Exception("test exception message");
Channel.GroupListener listener = Analytics.getInstance().getChannelListener();
listener.onBeforeSending(testEventLog);
listener.onSuccess(testEventLog);
listener.onFailure(testEventLog, testException);
verify(analyticsListener, never()).onBeforeSending(any(EventLog.class));
verify(analyticsListener, never()).onSendingSucceeded(any(EventLog.class));
verify(analyticsListener, never()).onSendingFailed(any(EventLog.class), any(Exception.class));
}
Aggregations