@Test public void testOnBackPressed() { shadowOf(activity).clickMenuItem(android.R.id.home); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); assertThat(activity).isFinishing(); }
@Override public void onBackPressed() { mAlertDialogBuilder .init(this) .setMessage(mSending ? R.string.confirm_no_waiting : R.string.confirm_no_submit) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> SubmitActivity.super.onBackPressed()) .show(); }
SubmitActivity extends InjectableActivity { @Override public void onBackPressed() { mAlertDialogBuilder .init(this) .setMessage(mSending ? R.string.confirm_no_waiting : R.string.confirm_no_submit) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> SubmitActivity.super.onBackPressed()) .show(); } }
SubmitActivity extends InjectableActivity { @Override public void onBackPressed() { mAlertDialogBuilder .init(this) .setMessage(mSending ? R.string.confirm_no_waiting : R.string.confirm_no_submit) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> SubmitActivity.super.onBackPressed()) .show(); }  }
SubmitActivity extends InjectableActivity { @Override public void onBackPressed() { mAlertDialogBuilder .init(this) .setMessage(mSending ? R.string.confirm_no_waiting : R.string.confirm_no_submit) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> SubmitActivity.super.onBackPressed()) .show(); }  @Override boolean onCreateOptionsMenu(Menu menu); @Override boolean onPrepareOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); @Override void onBackPressed(); }
SubmitActivity extends InjectableActivity { @Override public void onBackPressed() { mAlertDialogBuilder .init(this) .setMessage(mSending ? R.string.confirm_no_waiting : R.string.confirm_no_submit) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> SubmitActivity.super.onBackPressed()) .show(); }  @Override boolean onCreateOptionsMenu(Menu menu); @Override boolean onPrepareOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); @Override void onBackPressed();  }