ManifestUtils { @VisibleForTesting static void displayWarningForMissingActivities(@NonNull final Context context, @NonNull final List<Class<? extends Activity>> requiredActivities) { final List<Class<? extends Activity>> undeclaredActivities = filterDeclaredActivities(context, requiredActivities, false); if (undeclaredActivities.isEmpty()) { return; } logWarningToast(context); logMissingActivities(undeclaredActivities); } private  ManifestUtils(); static void checkWebViewActivitiesDeclared(@NonNull final Context context); static void checkNativeActivitiesDeclared(@NonNull final Context context); static boolean isDebuggable(@NonNull final Context context);  }
@Test public void displayWarningForMissingActivities_withAllActivitiesDeclared_shouldNotShowLogOrToast() throws Exception { Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidVideoPlayerActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubBrowser.class), mockResolveInfo); ShadowLog.setupLogging(); setDebugMode(true); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); assertThat(ShadowLog.getLogs()).isEmpty(); }
@Test public void displayWarningForMissingActivities_withOneMissingActivity_shouldLogOnlyThatOne() throws Exception { Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidVideoPlayerActivity.class), mockResolveInfo); ShadowLog.setupLogging(); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); assertLogIncludes("com.mopub.common.MoPubBrowser"); assertLogDoesntInclude( "com.mopub.mobileads.MoPubActivity", "com.mopub.mobileads.MraidActivity", "com.mopub.mobileads.MraidVideoPlayerActivity" ); }
@Test public void displayWarningForMissingActivities_withAllMissingActivities_shouldLogMessage() throws Exception { setDebugMode(true); ShadowLog.setupLogging(); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); final List<ShadowLog.LogItem> logs = ShadowLog.getLogs(); assertLogIncludes( "com.mopub.mobileads.MoPubActivity", "com.mopub.mobileads.MraidActivity", "com.mopub.mobileads.MraidVideoPlayerActivity", "com.mopub.common.MoPubBrowser" ); }
@Test public void displayWarningForMissingActivities_withMissingActivities_withDebugTrue_shouldShowToast() throws Exception { setDebugMode(true); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNotNull(); final String toastText = ShadowToast.getTextOfLatestToast(); assertThat(toastText).isEqualTo("ERROR: YOUR MOPUB INTEGRATION IS INCOMPLETE.\nCheck logcat and update your AndroidManifest.xml with the correct activities and configuration."); }
@Test public void displayWarningForMissingActivities_withMissingActivities_withDebugFalse_shouldNotShowToast() throws Exception { setDebugMode(false); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); }