@Test public void startWithoutTitle() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PictureViewActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithFile(File file) throws IOException { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putString("file", file.getAbsolutePath()); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PictureViewActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
@Test public void startWithoutProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyOverviewActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithMissingProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", 0); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyOverviewActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithProperty(Property property) { long id = db.insertProperty(property); Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", id); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyOverviewActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
@Test public void startWithoutProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertySummaryActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithMissingProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", 0); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertySummaryActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithProperty(Property property) { long id = db.insertProperty(property); Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", id); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertySummaryActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
private ActivityController startWithProperty(Property property) { long id = db.insertProperty(property); Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", id); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyPicturesActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
@Test public void startWithoutProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyPicturesActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithMissingProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", 0); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyPicturesActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithoutRequest() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(DictionaryActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithRequest(DictionaryItem item) { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putInt("title", item.titleId); bundle.putInt("definition", item.definitionId); if(item.formulaId != null) { bundle.putInt("formula", item.formulaId); } intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(DictionaryActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
@Test public void startWithoutProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyProjectionsActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithMissingProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", 0); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyProjectionsActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithProperty(Property property) { long id = db.insertProperty(property); Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", id); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyProjectionsActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
@Test public void startWithMissingProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", 0); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyNotesActivity.class, intent).create(); Activity activity = (Activity)controller.get(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithNotes(String notes) { Property property = new Property(); property.notes = notes; long id = db.insertProperty(property); Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", id); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyNotesActivity.class, intent).create(); Activity activity = (Activity)controller.get(); assertTrue(activity.isFinishing() == false); controller.start(); controller.visible(); controller.resume(); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
@Test public void startWithoutProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyWorksheetActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithMissingProperty() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", 0); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyWorksheetActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithProperty(Property property) { long id = db.insertProperty(property); Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", id); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyWorksheetActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
@Test public void startWithoutTitle() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putInt("description", R.string.app_name); bundle.putSerializable("items", new HashMap<String, Integer>()); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(ItemizeActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithoutDescription() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putInt("title", R.string.app_name); bundle.putSerializable("items", new HashMap<String, Integer>()); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(ItemizeActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
@Test public void startWithoutMap() { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putInt("title", R.string.app_name); bundle.putInt("description", R.string.app_name); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(ItemizeActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); assertTrue(activity.isFinishing()); String latestToast = ShadowToast.getTextOfLatestToast(); assertNotNull(latestToast); }
private ActivityController startWithMap(Map<String, Integer> map) { Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putInt("title", R.string.app_name); bundle.putInt("description", R.string.app_name); bundle.putSerializable("items", new HashMap<>(map)); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(ItemizeActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
private ActivityController startWithProperty(Property property) { long id = db.insertProperty(property); Intent intent = new Intent(); final Bundle bundle = new Bundle(); bundle.putLong("id", id); intent.putExtras(bundle); ActivityController controller = Robolectric.buildActivity(PropertyViewActivity.class, intent).create(); Activity activity = (Activity)controller.get(); controller.start(); controller.visible(); controller.resume(); assertTrue(activity.isFinishing() == false); String latestToast = ShadowToast.getTextOfLatestToast(); assertNull(latestToast); return controller; }
private void checkRuntimeException(int buttonId) { when(taskValidation .isNewNameValid(any(String.class))) .thenReturn(new ValidationResult(ValidationStatus.VALID)); when(taskValidation .isDurationValid(any(String.class))) .thenReturn(new ValidationResult(ValidationStatus.VALID)); when(taskTemplateRepository .create(any(String.class), any(Integer.class), any(Long.class), any(Long.class))) .thenThrow(new RuntimeException()); Button button = (Button) activity.findViewById(buttonId); button.performClick(); String expectedMessage = activity.getResources() .getString(R.string.save_task_error_message); assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage)); }
@Test public void testParseFailed() { assertThat(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_font_options)).isNotVisible(); assertThat((View) activity.findViewById(R.id.progress)).isVisible(); verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture()); callback.getValue().onResponse(null); reset(readabilityClient); assertThat(ShadowToast.getTextOfLatestToast()) .contains(activity.getString(R.string.readability_failed)); WebView webView = (WebView) activity.findViewById(R.id.web_view); shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank"); assertThat(ShadowWebView.getLastGlobalLoadedUrl()) .contains("http://example.com/article.html"); assertThat(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_font_options)).isNotVisible(); controller.pause().stop().destroy(); }
@Test public void testSubmitError() { ((EditText) activity.findViewById(R.id.edittext_title)).setText("title"); ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com"); shadowOf(activity).clickMenuItem(R.id.menu_send); ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE) .performClick(); verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"), eq(true), submitCallback.capture()); Uri redirect = Uri.parse(BuildConfig.APPLICATION_ID + "://item?id=1234"); UserServices.Exception exception = new UserServices.Exception(R.string.item_exist); exception.data = redirect; submitCallback.getValue().onError(exception); assertEquals(activity.getString(R.string.item_exist), ShadowToast.getTextOfLatestToast()); assertThat(shadowOf(activity).getNextStartedActivity()) .hasAction(Intent.ACTION_VIEW) .hasData(redirect); }
@Test public void testNavButtonHint() { PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_comments)) .putBoolean(activity.getString(R.string.pref_navigation), true) .apply(); startWithIntent(); View navButton = activity.findViewById(R.id.navigation_button); assertThat(navButton).isVisible(); ((GestureDetector.SimpleOnGestureListener) getDetector(navButton).getListener()) .onSingleTapConfirmed(mock(MotionEvent.class)); assertThat(ShadowToast.getTextOfLatestToast()) .contains(activity.getString(R.string.hint_nav_short)); }
@Test public void testNavButtonDrag() { PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_comments)) .putBoolean(activity.getString(R.string.pref_navigation), true) .apply(); startWithIntent(); View navButton = activity.findViewById(R.id.navigation_button); assertThat(navButton).isVisible(); getDetector(navButton).getListener().onLongPress(mock(MotionEvent.class)); assertThat(ShadowToast.getTextOfLatestToast()) .contains(activity.getString(R.string.hint_drag)); MotionEvent motionEvent = mock(MotionEvent.class); when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_MOVE); when(motionEvent.getRawX()).thenReturn(1f); when(motionEvent.getRawY()).thenReturn(1f); shadowOf(navButton).getOnTouchListener().onTouch(navButton, motionEvent); motionEvent = mock(MotionEvent.class); when(motionEvent.getAction()).thenReturn(MotionEvent.ACTION_UP); shadowOf(navButton).getOnTouchListener().onTouch(navButton, motionEvent); assertThat(navButton).hasX(1f).hasY(1f); }
@Test public void shouldSetEmergencyViewWhenRnrIsEmergency() { LMISTestApp.getInstance().setCurrentTimeMillis(DateUtil.parseString("2015-04-21 17:30:00", DateUtil.DATE_TIME_FORMAT).getTime()); RnRForm rnRForm = VIARequisitionFragment.presenter.getRnRForm(); rnRForm.setEmergency(true); VIARequisitionFragment.refreshRequisitionForm(rnRForm); VIARequisitionFragment.consultationView.findViewById(R.id.et_external_consultations_performed).performClick(); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("This information is not used when creating an emergency requisition"); assertThat(((TextView) VIARequisitionFragment.kitView.findViewById(R.id.et_via_kit_received_hf)).getText()).isEqualTo(StringUtils.EMPTY); assertThat(((TextView) VIARequisitionFragment.consultationView.findViewById(R.id.via_rnr_header)).getText()).isEqualTo("Emergency requisition balancete"); assertThat(VIARequisitionFragment.getActivity().getTitle().toString()).isEqualTo("Emergency requisition - 21 Apr"); }
@Test public void shouldShowToastWhenMoreThanLimitChecked() throws Exception { ArrayList<InventoryViewModel> inventoryViewModels = getInventoryViewModels(); for (InventoryViewModel model : inventoryViewModels) { model.setChecked(true); } inventoryViewModels.add(new InventoryViewModel(new ProductBuilder().setPrimaryName("Product name").setCode(String.valueOf("code")).build())); activity.mAdapter.refreshList(inventoryViewModels); activity.mAdapter.notifyDataSetChanged(); SelectEmergencyProductsViewHolder viewHolder = activity.mAdapter.onCreateViewHolder(new LinearLayout(activity), 0); activity.mAdapter.onBindViewHolder(viewHolder, 10); viewHolder.itemView.findViewById(R.id.touchArea_checkbox).performClick(); assertThat(ShadowToast.getTextOfLatestToast(), is("You can only select 10 products for an emergency requisition")); }
@Ignore("MRAID 2.0") @Test public void showUserDownloadImageAlert_withAppContext_shouldToastAndDownloadImage() throws Exception { response = new TestHttpResponseWithHeaders(200, FAKE_IMAGE_DATA); Robolectric.addPendingHttpResponse(response); assertThat(ShadowToast.shownToastCount()).isEqualTo(0); subject.storePicture(context.getApplicationContext(), IMAGE_URI_VALUE, mraidCommandFailureListener); ThreadUtils.pause(TIME_TO_PAUSE_FOR_NETWORK); assertThat(ShadowToast.shownToastCount()).isEqualTo(1); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("Downloading image to Picture gallery..."); Robolectric.runUiThreadTasks(); assertThat(expectedFile.exists()).isTrue(); assertThat(expectedFile.length()).isEqualTo(FAKE_IMAGE_DATA.length()); }
@Ignore("MRAID 2.0") @Test public void showUserDownloadImageAlert_withAppContext_whenDownloadImageFails_shouldDisplayFailureToastAndNotDownloadImage() throws Exception { response = new TestHttpResponseWithHeaders(200, FAKE_IMAGE_DATA); Robolectric.addPendingHttpResponse(response); assertThat(ShadowToast.shownToastCount()).isEqualTo(0); subject.storePicture(context, "this is an invalid image url and cannot be downloaded", mraidCommandFailureListener); ThreadUtils.pause(TIME_TO_PAUSE_FOR_NETWORK); assertThat(ShadowToast.shownToastCount()).isEqualTo(1); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("Downloading image to Picture gallery..."); Robolectric.runUiThreadTasks(); assertThat(ShadowToast.shownToastCount()).isEqualTo(2); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("Image failed to download."); assertThat(expectedFile.exists()).isFalse(); assertThat(expectedFile.length()).isEqualTo(0); }
@SuppressWarnings("unchecked") @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withAllActivitiesConfigured_shouldNotLogOrShowToast() throws Exception { ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(true); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); 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.displayWarningForMisconfiguredActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); assertThat(ShadowLog.getLogs()).isEmpty(); }
@SuppressWarnings("unchecked") @Config(reportSdk = Build.VERSION_CODES.HONEYCOMB_MR1) @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withMissingScreenSize_withApiLessThan13_shouldNotLogOrShowToast() throws Exception { ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(false); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); ShadowLog.setupLogging(); setDebugMode(true); ManifestUtils.displayWarningForMisconfiguredActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); assertThat(ShadowLog.getLogs()).isEmpty(); }
@SuppressWarnings("unchecked") @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withMissingScreenSize_withTargetApiLessThan13_shouldNotLogOrShowToast() throws Exception { // Set target API to < 13 ApplicationInfo applicationInfo = context.getApplicationInfo(); applicationInfo.targetSdkVersion = Build.VERSION_CODES.HONEYCOMB_MR1; when(context.getApplicationInfo()).thenReturn(applicationInfo); ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(false); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); ShadowLog.setupLogging(); setDebugMode(true); ManifestUtils.displayWarningForMisconfiguredActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); assertThat(ShadowLog.getLogs()).isEmpty(); }
@SuppressWarnings("unchecked") @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withMisconfiguredActivities_withDebugTrue_shouldShowToast() throws Exception { ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(false); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(false); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(false); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); setDebugMode(true); ManifestUtils.displayWarningForMisconfiguredActivities(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."); }
@SuppressWarnings("unchecked") @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withMisconfiguredActivities_withDebugFalse_shouldNotShowToast() throws Exception { ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(false); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(false); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(false); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); setDebugMode(false); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); }