@Test public void invalidWriteKeyFromResourcesThrowsException() throws Exception { mockWriteKeyInResources(context, null); try { Analytics.with(context); fail("Null writeKey should throw exception."); } catch (IllegalArgumentException expected) { assertThat(expected).hasMessage("writeKey must not be null or empty."); } mockWriteKeyInResources(context, ""); try { Analytics.with(context); fail("Empty writeKey should throw exception."); } catch (IllegalArgumentException expected) { assertThat(expected).hasMessage("writeKey must not be null or empty."); } mockWriteKeyInResources(context, " "); try { Analytics.with(context); fail("blank writeKey should throw exception."); } catch (IllegalArgumentException expected) { assertThat(expected).hasMessage("writeKey must not be null or empty."); } }
@Override public void initialize(Analytics analytics, ValueMap settings) throws IllegalStateException { log = analytics.getLogger().newLogger(AMPLITUDE_KEY); trackAllPages = settings.getBoolean("trackAllPages", false); trackCategorizedPages = settings.getBoolean("trackCategorizedPages", false); trackNamedPages = settings.getBoolean("trackNamedPages", false); boolean trackSessionEvents = settings.getBoolean("trackSessionEvents", false); String apiKey = settings.getString("apiKey"); amplitude = provider.get(); amplitude.initialize(analytics.getApplication(), apiKey); log.verbose("AmplitudeClient.getInstance().initialize(context, %s);", apiKey); amplitude.enableForegroundTracking(analytics.getApplication()); log.verbose("AmplitudeClient.getInstance().enableForegroundTracking(context);"); amplitude.trackSessionEvents(trackSessionEvents); log.verbose("AmplitudeClient.getInstance().trackSessionEvents(%s);", trackSessionEvents); }
@Override public Integration<?> create(ValueMap settings, Analytics analytics) { Logger logger = analytics.logger(GOOGLE_ANALYTICS_KEY); if (!hasPermission( analytics.getApplication(), Manifest.permission.ACCESS_NETWORK_STATE)) { logger.debug("ACCESS_NETWORK_STATE is required for Google Analytics."); return null; } String mobileTrackingId = settings.getString("mobileTrackingId"); if (isNullOrEmpty(mobileTrackingId)) { logger.debug("mobileTrackingId is required for Google Analytics."); return null; } Context context = analytics.getApplication(); com.google.android.gms.analytics.GoogleAnalytics ga = com.google.android.gms.analytics.GoogleAnalytics.getInstance(context); GoogleAnalytics googleAnalytics = new DefaultGoogleAnalytics(ga); return new GoogleAnalyticsIntegration(context, googleAnalytics, settings, logger); }
@Before public void setUp() throws PackageManager.NameNotFoundException { initMocks(this); mockStatic(MoEHelper.class); when(analytics.getApplication()).thenReturn(context); when(context.getPackageManager()).thenReturn(manager); when(activity.getPackageManager()).thenReturn(manager); when(manager.getApplicationInfo(context.getPackageName(), 0)).thenReturn(applicationInfo); when(context.getApplicationContext()).thenReturn(RuntimeEnvironment.application); integration = new MoEngageIntegration( analytics, new ValueMap().putValue("pushSenderId", "12324441").putValue("apiKey", "ASJKSLJAL")); integration.helper = moeHelper; }