RnRFormListActivity extends BaseReportListActivity { protected void checkAndGotoEmergencyPage() { int dayOfMonth = new DateTime(LMISApp.getInstance().getCurrentTimeMillis()).getDayOfMonth(); if (dayOfMonth >= Period.INVENTORY_BEGIN_DAY && dayOfMonth < Period.INVENTORY_END_DAY_NEXT) { ToastUtil.showForLongTime(R.string.msg_create_emergency_date_invalid); return; } loading(); presenter.hasMissedPeriod().subscribe(new Subscriber<Boolean>() { @Override public void onCompleted() { loaded(); } @Override public void onError(Throwable e) { loaded(); ToastUtil.show(e.getMessage()); } @Override public void onNext(Boolean hasMissed) { if (hasMissed) { ToastUtil.showForLongTime(R.string.msg_create_emergency_has_missed); } else { startActivityForResult(SelectEmergencyProductsActivity.getIntentToMe(RnRFormListActivity.this), Constants.REQUEST_FROM_RNR_LIST_PAGE); } } }); }  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 shouldShowToastWhenDateNotInEmergencyDate() throws Exception { LMISTestApp.getInstance().setCurrentTimeMillis(DateUtil.parseString("2015-05-18 17:30:00", DateUtil.DATE_TIME_FORMAT).getTime()); rnRFormListActivity.checkAndGotoEmergencyPage(); MatcherAssert.assertThat(ShadowToast.getTextOfLatestToast(), is("You are not allowed to create an emergency between 18th and 25th, please submit request using the monthly requisition form.")); }
@Test public void shouldShowToastWhenHasMissed() throws Exception { LMISTestApp.getInstance().setCurrentTimeMillis(DateUtil.parseString("2015-05-17 17:30:00", DateUtil.DATE_TIME_FORMAT).getTime()); Observable<Boolean> value = Observable.create(new Observable.OnSubscribe<Boolean>() { @Override public void call(Subscriber<? super Boolean> subscriber) { subscriber.onNext(true); } }); when(mockedPresenter.hasMissedPeriod()).thenReturn(value); rnRFormListActivity.checkAndGotoEmergencyPage(); MatcherAssert.assertThat(ShadowToast.getTextOfLatestToast(), is("You are not allowed to create an emergency requisition until you complete all your previous monthly requisitions.")); }
@Test public void shouldGotoEmergencyPage() throws Exception { LMISTestApp.getInstance().setCurrentTimeMillis(DateUtil.parseString("2015-05-17 17:30:00", DateUtil.DATE_TIME_FORMAT).getTime()); Observable<Boolean> value = Observable.create(new Observable.OnSubscribe<Boolean>() { @Override public void call(Subscriber<? super Boolean> subscriber) { subscriber.onNext(false); } }); when(mockedPresenter.hasMissedPeriod()).thenReturn(value); rnRFormListActivity.checkAndGotoEmergencyPage(); ShadowActivity shadowActivity = shadowOf(rnRFormListActivity); Intent startedIntent = shadowActivity.getNextStartedActivity(); ShadowIntent shadowIntent = shadowOf(startedIntent); MatcherAssert.assertThat(shadowIntent.getIntentClass().getCanonicalName(), equalTo(SelectEmergencyProductsActivity.class.getName())); }