@Test public void clickingOK_savesUsernameAndPasswordToGeneralPrefs() { FragmentScenario<ServerAuthDialogFragment> scenario = FragmentScenario.launch( ServerAuthDialogFragment.class, null, R.style.Theme_AppCompat, null ); scenario.onFragment(fragment -> { EditText username = fragment.getDialogView().findViewById(R.id.username_edit); EditText password = fragment.getDialogView().findViewById(R.id.password_edit); username.setText("Frederick Chilton"); password.setText("chesapeake"); ((AlertDialog) fragment.getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).performClick(); }); assertThat(generalPrefs.getString(GeneralKeys.KEY_USERNAME, null), is("Frederick Chilton")); assertThat(generalPrefs.getString(GeneralKeys.KEY_PASSWORD, null), is("chesapeake")); }
public View getDialogView() { return dialogView; }
ServerAuthDialogFragment extends DialogFragment { public View getDialogView() { return dialogView; } }
ServerAuthDialogFragment extends DialogFragment { public View getDialogView() { return dialogView; }  }
ServerAuthDialogFragment extends DialogFragment { public View getDialogView() { return dialogView; }  @Override void onAttach(@NonNull Context context); @NonNull @Override Dialog onCreateDialog(@Nullable Bundle savedInstanceState); View getDialogView(); }
ServerAuthDialogFragment extends DialogFragment { public View getDialogView() { return dialogView; }  @Override void onAttach(@NonNull Context context); @NonNull @Override Dialog onCreateDialog(@Nullable Bundle savedInstanceState); View getDialogView();  }