org.robolectric.shadows.ShadowToast Java Examples
The following examples show how to use
org.robolectric.shadows.ShadowToast.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestActivityTest.java From Awesome-WanAndroid with Apache License 2.0 | 6 votes |
@Test public void showToast() { Toast latestToast = ShadowToast.getLatestToast(); Assert.assertNull(latestToast); Button button = (Button) mTestActivity.findViewById(R.id.button2); button.performClick(); latestToast = ShadowToast.getLatestToast(); Assert.assertNotNull(latestToast); ShadowToast shadowToast = Shadows.shadowOf(latestToast); ShadowLog.d("toast_time", shadowToast.getDuration() + ""); Assert.assertEquals(Toast.LENGTH_SHORT, shadowToast.getDuration()); Assert.assertEquals("hahaha", ShadowToast.getTextOfLatestToast()); }
Example #2
Source File: SubmitActivityTest.java From materialistic with Apache License 2.0 | 6 votes |
@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); }
Example #3
Source File: TaskCreateActivityTest.java From friendly-plans with GNU General Public License v3.0 | 6 votes |
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), any(Integer.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)); }
Example #4
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 6 votes |
@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)); }
Example #5
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 6 votes |
@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); }
Example #6
Source File: MultimediaInflaterActivityTest.java From commcare-android with Apache License 2.0 | 6 votes |
/** * Ensure user sees invalid path toast when the file browser doesn't return a path uri */ @Test public void emptyFileSelectionTest() { MultimediaInflaterActivity multimediaInflaterActivity = Robolectric.buildActivity(MultimediaInflaterActivity.class) .create().start().resume().get(); ImageButton selectFileButton = multimediaInflaterActivity.findViewById( R.id.screen_multimedia_inflater_filefetch); selectFileButton.performClick(); Intent fileSelectIntent = new Intent(Intent.ACTION_GET_CONTENT); fileSelectIntent.setType("application/zip"); Intent emptyFileSelectResult = new Intent(); ShadowActivity shadowActivity = Shadows.shadowOf(multimediaInflaterActivity); shadowActivity.receiveResult(fileSelectIntent, Activity.RESULT_OK, emptyFileSelectResult); Assert.assertEquals(Localization.get("file.invalid.path"), ShadowToast.getTextOfLatestToast()); }
Example #7
Source File: LoginAdapterTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void instantiateItem_inActiveLoginButtonShouldToast() throws Exception { TestLoginListener listener = new TestLoginListener(); loginAdapter.setLoginListener(listener); View view = (View) loginAdapter.instantiateItem(new FrameLayout(application), PAGE_4); Button loginButton = (Button) view.findViewById(R.id.login_button); loginButton.performClick(); String expected = application.getString(R.string.agree_to_terms_please); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(expected); }
Example #8
Source File: PagerResultsFragmentTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void executeSearchOnMap_shouldToastAnError() { fragment.executeSearchOnMap(new SearchView(app), "Empire State Building"); verify(pelias).search(eq("Empire State Building"), anyDouble(), anyDouble(), peliasCallback.capture()); peliasCallback.getValue().failure(RetrofitError.unexpectedError("", null)); assertThat(getTextOfLatestToast()).isEqualTo(app.getString(R.string.generic_server_error)); assertThat(ShadowToast.getLatestToast()).hasDuration(Toast.LENGTH_LONG); }
Example #9
Source File: FeedbackActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testFailed() { ((EditText) activity.findViewById(R.id.edittext_title)).setText("title"); ((EditText) activity.findViewById(R.id.edittext_body)).setText("body"); activity.findViewById(R.id.feedback_button).performClick(); verify(feedbackClient).send(eq("title"), eq("body"), callback.capture()); callback.getValue().onSent(false); assertThat(activity).isNotFinishing(); assertEquals(activity.getString(R.string.feedback_failed), ShadowToast.getTextOfLatestToast()); controller.pause().stop().destroy(); }
Example #10
Source File: FeedbackActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testSuccessful() { ((EditText) activity.findViewById(R.id.edittext_title)).setText("title"); ((EditText) activity.findViewById(R.id.edittext_body)).setText("body"); activity.findViewById(R.id.feedback_button).performClick(); verify(feedbackClient).send(eq("title"), eq("body"), callback.capture()); callback.getValue().onSent(true); assertThat(activity).isFinishing(); assertEquals(activity.getString(R.string.feedback_sent), ShadowToast.getTextOfLatestToast()); controller.pause().stop().destroy(); }
Example #11
Source File: MapControllerTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void getLocation_shouldReturnNotBlowUpWhenPresetIsMalformed() throws Exception { enableFixedLocation(); setFixedLocation("malformed which makes no sense"); Location expected = new Location("expected"); controller.setLocation(expected); Location actual = controller.getLocation(); assertThat(ShadowToast.getTextOfLatestToast()) .isEqualTo(activity.getString(R.string.toast_fixed_location_is_malformed)); assertThat(actual).isEqualTo(expected); }
Example #12
Source File: MapControllerTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void getLocation_shouldReturnNotBlowUpWhenPresetIsMalformedWithComma() throws Exception { enableFixedLocation(); setFixedLocation("malformed, which makes no sense"); Location expected = new Location("expected"); controller.setLocation(expected); Location actual = controller.getLocation(); assertThat(ShadowToast.getTextOfLatestToast()) .isEqualTo(activity.getString(R.string.toast_fixed_location_is_malformed)); assertThat(actual).isEqualTo(expected); }
Example #13
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testVoteError() { Intent intent = new Intent(); intent.putExtra(ItemActivity.EXTRA_ITEM, new TestHnItem(1)); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume(); activity = controller.get(); activity.findViewById(R.id.vote_button).performClick(); verify(userServices).voteUp(any(Context.class), eq("1"), userServicesCallback.capture()); userServicesCallback.getValue().onError(new IOException()); assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast()); }
Example #14
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testVote() { Intent intent = new Intent(); intent.putExtra(ItemActivity.EXTRA_ITEM, new TestHnItem(1)); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume(); activity = controller.get(); activity.findViewById(R.id.vote_button).performClick(); verify(userServices).voteUp(any(Context.class), eq("1"), userServicesCallback.capture()); userServicesCallback.getValue().onDone(true); assertEquals(activity.getString(R.string.voted), ShadowToast.getTextOfLatestToast()); }
Example #15
Source File: RouteFragmentTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void createRouteTo_shouldToastIfNoRouteFound() throws Exception { Location testLocation = getTestLocation(100.0, 100.0); TestHelper.startFragment(fragment, act); fragment.createRouteTo(testLocation); fragment.failure(207); assertThat(ShadowToast.getTextOfLatestToast()) .isEqualTo(act.getString(R.string.no_route_found)); }
Example #16
Source File: ComposeActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testDelayedError() { doSend(); shadowOf(activity).clickMenuItem(android.R.id.home); replyCallback.getValue().onError(new IOException()); assertEquals(activity.getString(R.string.comment_failed), ShadowToast.getTextOfLatestToast()); }
Example #17
Source File: ComposeActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testDelayedSuccessfulResponse() { doSend(); shadowOf(activity).clickMenuItem(android.R.id.home); assertThat(activity).isFinishing(); replyCallback.getValue().onDone(true); assertEquals(activity.getString(R.string.comment_successful), ShadowToast.getTextOfLatestToast()); }
Example #18
Source File: ComposeActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testSendFailed() { doSend(); assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_send).isEnabled()); assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_quote).isVisible()); assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_save_draft).isEnabled()); assertFalse(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_discard_draft).isEnabled()); replyCallback.getValue().onError(new IOException()); assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_send).isEnabled()); assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_quote).isVisible()); assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_save_draft).isEnabled()); assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_discard_draft).isEnabled()); assertThat(activity).isNotFinishing(); assertEquals(activity.getString(R.string.comment_failed), ShadowToast.getTextOfLatestToast()); }
Example #19
Source File: SubmitActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testSubmitDelayedError() { ((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()); shadowOf(activity).clickMenuItem(android.R.id.home); ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE) .performClick(); submitCallback.getValue().onError(new IOException()); assertEquals(activity.getString(R.string.submit_failed), ShadowToast.getTextOfLatestToast()); }
Example #20
Source File: RobolectricActivityTest.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Test public void testButtonClickShouldShowToast() throws Exception { RobolectricActivity activity = Robolectric.buildActivity(RobolectricActivity.class).create().get(); Button view = (Button) activity.findViewById(R.id.showToast); assertNotNull(view); view.performClick(); assertThat(ShadowToast.getTextOfLatestToast(), equalTo("Lala") ); }
Example #21
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testSearch() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); activity.findViewById(R.id.button_find).performClick(); ViewSwitcher controlSwitcher = activity.findViewById(R.id.control_switcher); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(1); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); // no query EditText editText = activity.findViewById(R.id.edittext); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); // with results shadowWebView.setFindCount(1); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isEnabled(); activity.findViewById(R.id.button_next).performClick(); assertThat(shadowWebView.getFindIndex()).isEqualTo(1); activity.findViewById(R.id.button_clear).performClick(); assertThat(editText).isEmpty(); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(0); // with no results shadowWebView.setFindCount(0); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.no_matches)); }
Example #22
Source File: FavoriteActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Test public void testVoteItem() { shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick(); PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu(); Assert.assertNotNull(popupMenu); shadowOf(popupMenu).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote)); verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture()); userServicesCallback.getValue().onDone(true); assertEquals(activity.getString(R.string.voted), ShadowToast.getTextOfLatestToast()); }
Example #23
Source File: MainActivityTest.java From ActivityDiary with GNU General Public License v3.0 | 5 votes |
@Test public void currentActivity() throws Exception { /* now select an activity */ DiaryActivity someAct = new DiaryActivity(1, "Test", Color.BLACK); ActivityHelper.helper.insertActivity(someAct); assertNotNull(someAct); ActivityHelper.helper.setCurrentActivity(someAct); assertEquals(ActivityHelper.helper.getCurrentActivity(), someAct); MainActivity activity = Robolectric.setupActivity(MainActivity.class); View card = activity.findViewById(R.id.card); TextView nameView = (TextView) card.findViewById(R.id.activity_name); assertNotNull("Current activity Text available", nameView); assertEquals(nameView.getText(), "Test"); FloatingActionButton fabNoteEdit = (FloatingActionButton) activity.findViewById(R.id.fab_edit_note); FloatingActionButton fabAttachPicture = (FloatingActionButton) activity.findViewById(R.id.fab_attach_picture); assertNotNull("we have two FABs", fabNoteEdit); assertNotNull("we have two FABs", fabAttachPicture); fabNoteEdit.performClick(); DialogFragment dialogFragment = (DialogFragment) activity.getSupportFragmentManager() .findFragmentByTag("NoteEditDialogFragment"); assertNotNull(dialogFragment); ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS); assertNull(ShadowToast.getTextOfLatestToast()); fabAttachPicture.performClick(); ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS); assertNull(ShadowToast.getTextOfLatestToast()); }
Example #24
Source File: ToastFrameworkImplTest.java From Taskbar with Apache License 2.0 | 5 votes |
@Test public void testShow() { impl.show(); assertEquals(message, ShadowToast.getTextOfLatestToast()); Toast toast = ShadowToast.getLatestToast(); assertEquals(length, toast.getDuration()); assertEquals(Gravity.BOTTOM | Gravity.CENTER_VERTICAL, toast.getGravity()); assertEquals(0, toast.getXOffset()); assertEquals( context.getResources().getDimensionPixelSize(R.dimen.tb_toast_y_offset), toast.getYOffset() ); }
Example #25
Source File: ToastFrameworkImplTest.java From Taskbar with Apache License 2.0 | 5 votes |
@Test public void testCancel() { impl.show(); ShadowToast toast = Shadows.shadowOf(ShadowToast.getLatestToast()); assertFalse(toast.isCancelled()); impl.cancel(); assertTrue(toast.isCancelled()); }
Example #26
Source File: UTest.java From Taskbar with Apache License 2.0 | 5 votes |
@Test public void testShowToast() { U.showToast(context, R.string.tb_pin_shortcut_not_supported); Toast toast = ShadowToast.getLatestToast(); assertEquals(Toast.LENGTH_SHORT, toast.getDuration()); assertEquals( context.getResources().getString(R.string.tb_pin_shortcut_not_supported), ShadowToast.getTextOfLatestToast() ); }
Example #27
Source File: UTest.java From Taskbar with Apache License 2.0 | 5 votes |
@Test public void testShowLongToast() { U.showToastLong(context, R.string.tb_pin_shortcut_not_supported); Toast toast = ShadowToast.getLatestToast(); assertEquals(Toast.LENGTH_LONG, toast.getDuration()); assertEquals( context.getResources().getString(R.string.tb_pin_shortcut_not_supported), ShadowToast.getTextOfLatestToast() ); }
Example #28
Source File: UTest.java From Taskbar with Apache License 2.0 | 5 votes |
@Test public void testCancelToast() { U.showToastLong(context, R.string.tb_pin_shortcut_not_supported); ShadowToast shadowToast = Shadows.shadowOf(ShadowToast.getLatestToast()); assertFalse(shadowToast.isCancelled()); U.cancelToast(); assertTrue(shadowToast.isCancelled()); }
Example #29
Source File: TaskCreateActivityTest.java From friendly-plans with GNU General Public License v3.0 | 5 votes |
@Test public void whenActivityResultIsCalledWithNonExistingPictureDataExpectToastWithErrorMessageIsShown() { fragment.onActivityResult( AssetType.PICTURE.ordinal(), FilePickerActivity.RESULT_OK, new Intent() ); String expectedMessage = activity.getResources().getString(R.string.picking_file_error); assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage)); }
Example #30
Source File: StepCreateFragmentTest.java From friendly-plans with GNU General Public License v3.0 | 5 votes |
@Test public void whenClickPlayButtonWithoutSoundChosenExpectToastToBeDisplayed() { ImageButton playSound = (ImageButton) activity.findViewById(R.id.id_btn_play_step_sound); playSound.performClick(); String expectedMessage = activity.getResources().getString(R.string.no_file_to_play_error); assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage)); }