RapidFtrActivity extends Activity { protected BroadcastReceiver getBroadcastReceiver() { return networkChangeReceiver; }  RapidFtrApplication getContext(); void searchChildrenTabListener(View view); void createEnquiryTabListener(View view); void viewAllEnquiryTabListener(View view); void registerChildTabListener(View view); void viewAllChildrenListener(View view); void addResultListener(int requestCode, ResultListener listener); @Override void onActivityResult(int requestCode, int resultCode, Intent data); @Override boolean onCreateOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); void getServerAndSync(); void hideEnquiriesTabIfRapidReg(); static final String LOGOUT_INTENT_FILTER; }
@Test public void shouldShowToastMsgIfSyncIsInProgressAndNetworkLost() { RapidFtrActivity rapidFtrActivity = spy(new ViewAllChildrenActivity()); BroadcastReceiver receiver = rapidFtrActivity.getBroadcastReceiver(); Intent mockIntent = mock(Intent.class); NetworkInfo mockNetworkInfo = mock(NetworkInfo.class); doReturn(mockNetworkInfo).when(mockIntent).getParcelableExtra(EXTRA_NETWORK_INFO); doReturn(false).when(mockNetworkInfo).isConnected(); RapidFtrApplication.getApplicationInstance().setAsyncTaskWithDialog(new AsyncTaskWithDialog() { @Override public void cancel() { } @Override protected Object doInBackground(Object... objects) { return null; } }); receiver.onReceive(rapidFtrActivity, mockIntent); MatcherAssert.assertThat(ShadowToast.getTextOfLatestToast(), equalTo(rapidFtrActivity.getString(R.string.network_down))); }