AsyncTaskSentenceLoadExecutor implements SentenceLoadExecutor<List<? extends Sentence>, Void>, LoaderManager.LoaderCallbacks<List<? extends Sentence>> { public void loadSentences(boolean isFirstLoad, boolean favorite, UseCase.UseCaseCallback<List<? extends Sentence>, Void> callback) { mCaseCallback = callback; Loader loader = mLoaderManager.getLoader(SENTENCES_QUERY); if (isFirstLoad || loader == null) { Bundle args = new Bundle(); args.putBoolean(IS_FAVORITE, favorite); mLoaderManager.initLoader(SENTENCES_QUERY, args, this); } else { loader.onContentChanged(); } } AsyncTaskSentenceLoadExecutor(Context context, LoaderManager loaderManager); void loadSentences(boolean isFirstLoad, boolean favorite, UseCase.UseCaseCallback<List<? extends Sentence>, Void> callback); @Override Loader<List<? extends Sentence>> onCreateLoader(int id, Bundle args); @Override void onLoadFinished(Loader<List<? extends Sentence>> loader, List<? extends Sentence> data); @Override void onLoaderReset(Loader<List<? extends Sentence>> loader);  }
@Test public void testLoadSentencesFirst() { mAsyncTaskSentenceLoadExecutor.loadSentences(true, true, null); verify(mLoaderManager).getLoader(anyInt()); verify(mLoaderManager).initLoader(anyInt(), mBundleCaptor.capture(), eq(mAsyncTaskSentenceLoadExecutor)); Bundle bundle = mBundleCaptor.getValue(); assertTrue(bundle != null); }
@Test public void testLoadSentencesNotFirst1() { mAsyncTaskSentenceLoadExecutor.loadSentences(false, false, null); verify(mLoaderManager).getLoader(anyInt()); verify(mLoaderManager).initLoader(anyInt(), mBundleCaptor.capture(), eq(mAsyncTaskSentenceLoadExecutor)); Bundle bundle = mBundleCaptor.getValue(); assertFalse(bundle.getBoolean("IS_FAVORITE")); }
@Test public void testLoadSentencesNotFirst2() { when(mLoaderManager.getLoader(anyInt())).thenReturn(mLoader); mAsyncTaskSentenceLoadExecutor.loadSentences(false, true, null); verify(mLoaderManager).getLoader(anyInt()); verify(mLoaderManager, atMost(0)).initLoader(anyInt(), mBundleCaptor.capture(), eq(mAsyncTaskSentenceLoadExecutor)); verify(mLoader).onContentChanged(); }