DEFetchReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { LogUtils.v(Constants.TAG, "DEFetchReceiver: " + intent); if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()) && !NetworkUtils.isNetworkAvailable()) { LogUtils.d(Constants.TAG, "Network is not available, abort fetching."); return; } DefaultUseCaseHandler.createParallelUCHandler().execute(getAutoFetchTodaysSentenceUC(context)); }  @Override void onReceive(Context context, Intent intent); @VisibleForTesting AutoFetchTodaysSentenceUC getAutoFetchTodaysSentenceUC(Context context);  }
@Test public void testOnReceive_CONNECTIVITY_ACTION_AvailableNetwork() { doReturn(true).when(mMockNetworkChecker).isNetworkAvailable(); doReturn(ConnectivityManager.CONNECTIVITY_ACTION).when(mIntent).getAction(); mDEFetchReceiver.onReceive(null, mIntent); waitToRun(100); verify(mAutoFetchTodaysSentenceUC).run(); }
@Test public void testOnReceive_CONNECTIVITY_ACTION_NotAvailableNetwork() { doReturn(false).when(mMockNetworkChecker).isNetworkAvailable(); doReturn(ConnectivityManager.CONNECTIVITY_ACTION).when(mIntent).getAction(); mDEFetchReceiver.onReceive(null, mIntent); waitToRun(100); verify(mAutoFetchTodaysSentenceUC, atMost(0)).run(); }
@Test public void testOnReceive_OTHER_ACTION_AvailableNetwork() { doReturn(true).when(mMockNetworkChecker).isNetworkAvailable(); mDEFetchReceiver.onReceive(null, mIntent); waitToRun(100); verify(mAutoFetchTodaysSentenceUC).run(); }