DEFetchService extends IntentService { @Override protected void onHandleIntent(Intent intent) { if (intent != null) { getSentenceDataRepository().fetchTodaysSentence(intent.getBooleanExtra(BOOLEAN_EXTRAL_IS_MANUAL, false)); } } DEFetchService(); @VisibleForTesting SentenceDataRepository getSentenceDataRepository(); static final String BOOLEAN_EXTRAL_IS_MANUAL; }
@Test public void testOnNullIntent() { mDEFetchService.onHandleIntent(null); verify(mSentenceDataRepository, atMost(0)).fetchTodaysSentence(anyBoolean()); }
@Test public void testOnIntent1() { mDEFetchService.onHandleIntent(mIntent); verify(mSentenceDataRepository).fetchTodaysSentence(false); }
@Test public void testOnIntent2() { doReturn(true).when(mIntent).getBooleanExtra("boolean_extral_is_manual", false); mDEFetchService.onHandleIntent(mIntent); verify(mSentenceDataRepository).fetchTodaysSentence(true); }