@Test public void shouldKeepListOfOpenedDialogs() throws Exception { assertEquals(0, ShadowDialog.getShownDialogs().size()); TestDialog dialog = new TestDialog(context); dialog.show(); assertEquals(1, ShadowDialog.getShownDialogs().size()); assertEquals(dialog, ShadowDialog.getShownDialogs().get(0)); TestDialog dialog2 = new TestDialog(context); dialog2.show(); assertEquals(2, ShadowDialog.getShownDialogs().size()); assertEquals(dialog2, ShadowDialog.getShownDialogs().get(1)); dialog.dismiss(); assertEquals(2, ShadowDialog.getShownDialogs().size()); ShadowDialog.reset(); assertEquals(0, ShadowDialog.getShownDialogs().size()); }
public void clickOnText(String text) { if (!clickOnText(inflatedView, text)) { throw new IllegalArgumentException("Text not found: " + text); } }
@Test public void getLatestDialog_shouldReturnARealDialog() throws Exception { assertThat(ShadowDialog.getLatestDialog()).isNull(); Dialog dialog = new Dialog(context); dialog.show(); assertThat(ShadowDialog.getLatestDialog()).isSameAs(dialog); }
@Test public void removeUsingTransaction_shouldDismissTheDialog() throws Exception { dialogFragment.show(fragmentManager, null); FragmentTransaction t = fragmentManager.beginTransaction(); t.remove(dialogFragment); t.commit(); Dialog dialog = ShadowDialog.getLatestDialog(); assertFalse(dialog.isShowing()); assertTrue(shadowOf(dialog).hasBeenDismissed()); }
@Resetter public static void reset() { setLatestDialog(null); shownDialogs.clear(); }
ShadowCookieManager.resetCookies(); ShadowDebug.reset(); ShadowDialog.reset(); if (org.robolectric.RuntimeEnvironment.getApiLevel() >= 17) ShadowDisplayManagerGlobal.reset(); ShadowDrawable.clearCorruptStreamSources();
@Override public void show() { super.show(); ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); shadowApplication.setLatestAlertDialog(this); }
@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(); }
@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); } }
@Implementation protected void show() { setLatestDialog(this); shownDialogs.add(realDialog); directlyOn(realDialog, Dialog.class).show(); }
public void reset() { ShadowAccountManager.reset(); ShadowAudioEffect.reset(); ShadowBackgroundThread.reset(); ShadowBinder.reset(); ShadowBitmapFactory.reset(); ShadowChoreographer.reset(); ShadowContentResolver.reset(); ShadowCookieManager.resetCookies(); ShadowDialog.reset(); ShadowDrawable.clearCorruptStreamSources(); ShadowEnvironment.reset(); ShadowLog.reset(); ShadowLooper.resetThreadLoopers(); ShadowMediaMetadataRetriever.reset(); ShadowMediaPlayer.resetStaticState(); ShadowMessage.reset(); ShadowMimeTypeMap.reset(); ShadowPendingIntent.reset(); ShadowPowerManager.reset(); ShadowProcess.reset(); ShadowRenderNodeAnimator.reset(); ShadowResourceManager.reset(); ShadowResources.reset(); ShadowSQLiteConnection.reset(); ShadowStatFs.reset(); ShadowTypeface.reset(); ShadowValueAnimator.reset(); }
@Override public void show() { super.show(); ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application); shadowApplication.setLatestAlertDialog(this); }
@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); }
@Test public void show_setsLatestDialog() { Dialog dialog = new Dialog(context); assertNull(ShadowDialog.getLatestDialog()); dialog.show(); assertSame(dialog, ShadowDialog.getLatestDialog()); assertNull(ShadowAlertDialog.getLatestAlertDialog()); }
public void clickOnText(int textId) { if (inflatedView == null) { inflatedView = LayoutInflater.from(context).inflate(layoutId, null); } String text = realDialog.getContext().getResources().getString(textId); if (!clickOnText(inflatedView, text)) { throw new IllegalArgumentException("Text not found: " + text); } }
@Resetter public static void reset() { setLatestDialog(null); shownDialogs.clear(); }
ShadowContentResolver.reset(); ShadowCookieManager.resetCookies(); ShadowDialog.reset(); ShadowDrawable.clearCorruptStreamSources(); ShadowEnvironment.reset();
@Implementation public void show() { super.show(); shadowOf(RuntimeEnvironment.application).setLatestAlertDialog(this); }
protected String getDialogText() { MaterialDialog dialog = (MaterialDialog)ShadowDialog.getLatestDialog(); return dialog == null || dialog.getContentView() == null ? null : dialog.getContentView().getText().toString(); }
private boolean clickOnText(View view, String text) { ShadowView shadowView = Shadow.extract(view); if (text.equals(shadowView.innerText())) { view.performClick(); return true; } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { View child = viewGroup.getChildAt(i); if (clickOnText(child, text)) { return true; } } } return false; }