Search in sources :

Example 1 with AnalyticsListener

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));
}
Also used : Context(android.content.Context) AnalyticsListener(com.microsoft.appcenter.analytics.channel.AnalyticsListener) PageLog(com.microsoft.appcenter.analytics.ingestion.models.PageLog) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) Log(com.microsoft.appcenter.ingestion.models.Log) AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) Channel(com.microsoft.appcenter.channel.Channel) IOException(java.io.IOException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with AnalyticsListener

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));
}
Also used : AnalyticsListener(com.microsoft.appcenter.analytics.channel.AnalyticsListener) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) Channel(com.microsoft.appcenter.channel.Channel) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AnalyticsListener (com.microsoft.appcenter.analytics.channel.AnalyticsListener)2 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)2 Channel (com.microsoft.appcenter.channel.Channel)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Context (android.content.Context)1 PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)1 StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)1 Log (com.microsoft.appcenter.ingestion.models.Log)1 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1