Java Code Examples for org.robolectric.shadows.ShadowDialog#getLatestDialog()
The following examples show how to use
org.robolectric.shadows.ShadowDialog#getLatestDialog() .
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: NumericOptionItemTest.java From msdkui-android with Apache License 2.0 | 6 votes |
@Test public void testValueEditDialogPositive() { int newValue = 10; mNumericOptionItem.setLabel(getString(R.string.msdkui_violate_truck_options)); final TextView valueView = mNumericOptionItem.findViewById(R.id.numeric_item_value); assertNotNull(valueView); valueView.performClick(); AlertDialog alertDialog = (AlertDialog) ShadowDialog.getLatestDialog(); assertTrue(alertDialog.isShowing()); EditText valueEdit = alertDialog.findViewById(R.id.numeric_item_value_text); valueEdit.setText(String.valueOf(newValue)); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); assertEquals(newValue, mNumericOptionItem.getValue().intValue()); }
Example 2
Source File: NavFloatingActionButtonTest.java From materialistic with Apache License 2.0 | 6 votes |
@Test public void testKonami() { gestureListener.onFling(null, null, 0f, 1f); // down, invalid, should ignore gestureListener.onFling(null, null, 0f, -1f); // up gestureListener.onFling(null, null, 0f, 1f); // down, invalid, should reset gestureListener.onFling(null, null, 0f, -1f); // up gestureListener.onFling(null, null, 0f, -1f); // up gestureListener.onFling(null, null, 0f, 1f); // down gestureListener.onFling(null, null, 0f, 1f); // down gestureListener.onFling(null, null, -1f, 0f); // left gestureListener.onFling(null, null, 1f, 0f); // right gestureListener.onFling(null, null, -1f, 0f); // left gestureListener.onFling(null, null, 1f, 0f); // right gestureListener.onDoubleTap(null); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); shadowOf(dialog).clickOn(android.R.id.button1); // BUTTON_POSITIVE assertThat(shadowOf(RuntimeEnvironment.application).getNextStartedActivity()) .hasAction(Intent.ACTION_VIEW); }
Example 3
Source File: DirectoryChooserFragmentTest.java From droid-stealth with GNU General Public License v2.0 | 6 votes |
@Test public void testCreateDirectoryDialog() { final String directoryName = "mydir"; final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance( directoryName, null); startFragment(fragment, DirectoryChooserActivityMock.class); fragment.onOptionsItemSelected(new TestMenuItem() { @Override public int getItemId() { return R.id.new_folder_item; } }); final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog(); final ShadowAlertDialog shadowAlertDialog = Robolectric.shadowOf(dialog); assertEquals(shadowAlertDialog.getTitle(), "Create folder"); assertEquals(shadowAlertDialog.getMessage(), "Create new folder with name \"mydir\"?"); }
Example 4
Source File: NumericOptionItemTest.java From msdkui-android with Apache License 2.0 | 5 votes |
@Test public void testValueEditDialogNegative() { mNumericOptionItem.setLabel(getString(R.string.msdkui_violate_truck_options)); final TextView valueView = mNumericOptionItem.findViewById(R.id.numeric_item_value); assertNotNull(valueView); valueView.performClick(); AlertDialog alertDialog = (AlertDialog) ShadowDialog.getLatestDialog(); assertTrue(alertDialog.isShowing()); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); assertFalse(alertDialog.isShowing()); }
Example 5
Source File: PreferencesActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testHelp() { ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager() .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName())) .getPreferenceScreen() .findPreference(activity.getString(R.string.pref_volume_help)) .performClick(); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); assertThat((TextView) dialog.findViewById(R.id.alertTitle)) .hasText(R.string.pref_volume_title); }
Example 6
Source File: PreferencesActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testLazyLoadHelp() { ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager() .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName())) .getPreferenceScreen() .findPreference(activity.getString(R.string.pref_lazy_load_help)) .performClick(); Dialog dialog = ShadowDialog.getLatestDialog(); assertNotNull(dialog); assertThat((TextView) dialog.findViewById(R.id.alertTitle)) .hasText(R.string.pref_lazy_load_title); }
Example 7
Source File: DirectoryChooserFragmentTest.java From Android-DirectoryChooser with Apache License 2.0 | 5 votes |
@Test public void testCreateDirectoryDialogAllowFolderNameModification() { final String directoryName = "mydir"; final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance( DirectoryChooserConfig.builder() .newDirectoryName(directoryName) .initialDirectory("") .allowReadOnlyDirectory(false) .allowNewDirectoryNameModification(true) .build()); startFragment(fragment, DirectoryChooserActivityMock.class); fragment.onOptionsItemSelected(new TestMenuItem() { @Override public int getItemId() { return R.id.new_folder_item; } }); final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog(); final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog); assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder"); assertThat(ShadowDialog.getShownDialogs()).contains(dialog); final TextView msgView = (TextView) dialog.findViewById(R.id.msgText); assertThat(msgView).hasText("Create new folder with name \"mydir\"?"); final EditText editText = (EditText) dialog.findViewById(R.id.editText); assertThat(editText).isVisible(); assertThat(editText).hasTextString(directoryName); }
Example 8
Source File: DirectoryChooserFragmentTest.java From Android-DirectoryChooser with Apache License 2.0 | 5 votes |
@Test public void testCreateDirectoryDialogDisallowFolderNameModification() { final String directoryName = "mydir"; final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance( DirectoryChooserConfig.builder() .newDirectoryName(directoryName) .initialDirectory("") .allowReadOnlyDirectory(false) .allowNewDirectoryNameModification(false) .build()); startFragment(fragment, DirectoryChooserActivityMock.class); fragment.onOptionsItemSelected(new TestMenuItem() { @Override public int getItemId() { return R.id.new_folder_item; } }); final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog(); final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog); assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder"); assertThat(ShadowDialog.getShownDialogs()).contains(dialog); final TextView msgView = (TextView) dialog.findViewById(R.id.msgText); assertThat(msgView).hasText("Create new folder with name \"mydir\"?"); final EditText editText = (EditText) dialog.findViewById(R.id.editText); assertThat(editText).isGone(); }