RnRFormListActivity extends BaseReportListActivity { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != Activity.RESULT_OK) { return; } switch (requestCode) { case Constants.REQUEST_FROM_RNR_LIST_PAGE: loadForms(); break; case Constants.REQUEST_SELECT_PERIOD_END: Date periodEndDate = (Date) data.getSerializableExtra(Constants.PARAM_SELECTED_INVENTORY_DATE); boolean isMissedPeriod = data.getBooleanExtra(Constants.PARAM_IS_MISSED_PERIOD, false); createRequisition(periodEndDate, isMissedPeriod); break; } }  static Intent getIntentToMe(Context context, Constants.Program programCode); @Override void onActivityResult(int requestCode, int resultCode, Intent data); @Override boolean onCreateOptionsMenu(Menu menu); @Override boolean onPrepareOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); static final int DEFAULT_FORM_ID_OF_NOT_AUTHORIZED; }
@Test public void shouldGoToRequisitionPageWhenInvokeOnActivityResultWithSelectPeriodRequestCode() throws Exception { Intent data = new Intent(); Date inventoryDate = new Date(); data.putExtra(Constants.PARAM_SELECTED_INVENTORY_DATE, inventoryDate); data.putExtra(Constants.PARAM_IS_MISSED_PERIOD, true); intent.putExtra(Constants.PARAM_PROGRAM_CODE, Constants.Program.VIA_PROGRAM); rnRFormListActivity = Robolectric.buildActivity(RnRFormListActivity.class, intent).create().get(); rnRFormListActivity.onActivityResult(Constants.REQUEST_SELECT_PERIOD_END, Activity.RESULT_OK, data); Intent nextStartedIntent = ShadowApplication.getInstance().getNextStartedActivity(); assertNotNull(nextStartedIntent); assertEquals(nextStartedIntent.getComponent().getClassName(), VIARequisitionActivity.class.getName()); assertTrue(nextStartedIntent.getBooleanExtra(Constants.PARAM_IS_MISSED_PERIOD, false)); assertEquals(nextStartedIntent.getSerializableExtra(Constants.PARAM_SELECTED_INVENTORY_DATE), inventoryDate); }
@Test public void shouldRefreshUIWhenInvokeOnActivityResultWithRNRListRequestCode() throws Exception { rnRFormListActivity.onActivityResult(Constants.REQUEST_FROM_RNR_LIST_PAGE, Activity.RESULT_OK, new Intent()); verify(mockedPresenter, times(2)).loadRnRFormList(); }