@Test public void testCustomDispatcherFactory() { Dispatcher dispatcher = mock(Dispatcher.class); DispatcherFactory factory = mock(DispatcherFactory.class); when(factory.build(any(Tracker.class))).thenReturn(dispatcher); when(mMatomo.getDispatcherFactory()).thenReturn(factory); Tracker tracker = new Tracker(mMatomo, mTrackerBuilder); verify(factory).build(tracker); } }
@Test public void testCustomDispatcherFactory() { Dispatcher dispatcher = mock(Dispatcher.class); DispatcherFactory factory = mock(DispatcherFactory.class); when(factory.build(any(Tracker.class))).thenReturn(dispatcher); when(mMatomo.getDispatcherFactory()).thenReturn(factory); Tracker tracker = new Tracker(mMatomo, mTrackerBuilder); verify(factory).build(tracker); } }
@Test public void testSetDispatcherFactory() { final Matomo matomo = Matomo.getInstance(Robolectric.application); Dispatcher dispatcher = mock(Dispatcher.class); DispatcherFactory factory = mock(DispatcherFactory.class); when(factory.build(any(Tracker.class))).thenReturn(dispatcher); assertThat(matomo.getDispatcherFactory(), is(not(nullValue()))); matomo.setDispatcherFactory(factory); assertThat(matomo.getDispatcherFactory(), is(factory)); }
@Test public void testSetDispatcherFactory() { final Matomo matomo = Matomo.getInstance(Robolectric.application); Dispatcher dispatcher = mock(Dispatcher.class); DispatcherFactory factory = mock(DispatcherFactory.class); when(factory.build(any(Tracker.class))).thenReturn(dispatcher); assertThat(matomo.getDispatcherFactory(), is(not(nullValue()))); matomo.setDispatcherFactory(factory); assertThat(matomo.getDispatcherFactory(), is(factory)); }
@Before public void setup() { MockitoAnnotations.initMocks(this); when(mMatomo.getContext()).thenReturn(mContext); when(mMatomo.getTrackerPreferences(any(Tracker.class))).thenReturn(mTrackerPreferences); when(mMatomo.getPreferences()).thenReturn(mPreferences); when(mMatomo.getDispatcherFactory()).thenReturn(mDispatcherFactory); when(mDispatcherFactory.build(any(Tracker.class))).thenReturn(mDispatcher); when(mMatomo.getDeviceHelper()).thenReturn(mDeviceHelper); when(mDeviceHelper.getResolution()).thenReturn(new int[]{480, 800}); when(mDeviceHelper.getUserAgent()).thenReturn("aUserAgent"); when(mDeviceHelper.getUserLanguage()).thenReturn("en"); when(mTrackerBuilder.getApiUrl()).thenReturn(mApiUrl); when(mTrackerBuilder.getSiteId()).thenReturn(mSiteId); when(mTrackerBuilder.getTrackerName()).thenReturn(mTrackerName); when(mTrackerBuilder.getApplicationBaseUrl()).thenReturn("http://this.is.our.package/"); }
@Before public void setup() { MockitoAnnotations.initMocks(this); when(mMatomo.getContext()).thenReturn(mContext); when(mMatomo.getTrackerPreferences(any(Tracker.class))).thenReturn(mTrackerPreferences); when(mMatomo.getPreferences()).thenReturn(mPreferences); when(mMatomo.getDispatcherFactory()).thenReturn(mDispatcherFactory); when(mDispatcherFactory.build(any(Tracker.class))).thenReturn(mDispatcher); when(mMatomo.getDeviceHelper()).thenReturn(mDeviceHelper); when(mDeviceHelper.getResolution()).thenReturn(new int[]{480, 800}); when(mDeviceHelper.getUserAgent()).thenReturn("aUserAgent"); when(mDeviceHelper.getUserLanguage()).thenReturn("en"); when(mTrackerBuilder.getApiUrl()).thenReturn(mApiUrl); when(mTrackerBuilder.getSiteId()).thenReturn(mSiteId); when(mTrackerBuilder.getTrackerName()).thenReturn(mTrackerName); when(mTrackerBuilder.getApplicationBaseUrl()).thenReturn("http://this.is.our.package/"); }
protected Tracker(Matomo matomo, TrackerBuilder config) { mMatomo = matomo; mApiUrl = config.getApiUrl(); mSiteId = config.getSiteId(); mName = config.getTrackerName(); mDefaultApplicationBaseUrl = config.getApplicationBaseUrl(); new LegacySettingsPorter(mMatomo).port(this); mOptOut = getPreferences().getBoolean(PREF_KEY_TRACKER_OPTOUT, false); mDispatcher = mMatomo.getDispatcherFactory().build(this); String userId = getPreferences().getString(PREF_KEY_TRACKER_USERID, null); if (userId == null) { userId = UUID.randomUUID().toString(); getPreferences().edit().putString(PREF_KEY_TRACKER_USERID, userId).apply(); } mDefaultTrackMe.set(QueryParams.USER_ID, userId); mDefaultTrackMe.set(QueryParams.SESSION_START, DEFAULT_TRUE_VALUE); String resolution = DEFAULT_UNKNOWN_VALUE; int[] res = mMatomo.getDeviceHelper().getResolution(); if (res != null) resolution = String.format("%sx%s", res[0], res[1]); mDefaultTrackMe.set(QueryParams.SCREEN_RESOLUTION, resolution); mDefaultTrackMe.set(QueryParams.USER_AGENT, mMatomo.getDeviceHelper().getUserAgent()); mDefaultTrackMe.set(QueryParams.LANGUAGE, mMatomo.getDeviceHelper().getUserLanguage()); mDefaultTrackMe.set(QueryParams.VISITOR_ID, makeRandomVisitorId()); mDefaultTrackMe.set(QueryParams.URL_PATH, config.getApplicationBaseUrl()); }
protected Tracker(Matomo matomo, TrackerBuilder config) { mMatomo = matomo; mApiUrl = config.getApiUrl(); mSiteId = config.getSiteId(); mName = config.getTrackerName(); mDefaultApplicationBaseUrl = config.getApplicationBaseUrl(); new LegacySettingsPorter(mMatomo).port(this); mOptOut = getPreferences().getBoolean(PREF_KEY_TRACKER_OPTOUT, false); mDispatcher = mMatomo.getDispatcherFactory().build(this); String userId = getPreferences().getString(PREF_KEY_TRACKER_USERID, null); if (userId == null) { userId = UUID.randomUUID().toString(); getPreferences().edit().putString(PREF_KEY_TRACKER_USERID, userId).apply(); } mDefaultTrackMe.set(QueryParams.USER_ID, userId); mDefaultTrackMe.set(QueryParams.SESSION_START, DEFAULT_TRUE_VALUE); String resolution = DEFAULT_UNKNOWN_VALUE; int[] res = mMatomo.getDeviceHelper().getResolution(); if (res != null) resolution = String.format("%sx%s", res[0], res[1]); mDefaultTrackMe.set(QueryParams.SCREEN_RESOLUTION, resolution); mDefaultTrackMe.set(QueryParams.USER_AGENT, mMatomo.getDeviceHelper().getUserAgent()); mDefaultTrackMe.set(QueryParams.LANGUAGE, mMatomo.getDeviceHelper().getUserLanguage()); mDefaultTrackMe.set(QueryParams.VISITOR_ID, makeRandomVisitorId()); mDefaultTrackMe.set(QueryParams.URL_PATH, config.getApplicationBaseUrl()); }