AcademyRepository implements AcademyDataSource { @Override public LiveData<Resource<ModuleEntity>> getContent(String moduleId) { return new NetworkBoundResource<ModuleEntity, ContentResponse>(appExecutors) { @Override protected LiveData<ModuleEntity> loadFromDB() { return localDataSource.getModuleWithContent(moduleId); } @Override protected Boolean shouldFetch(ModuleEntity moduleEntity) { return (moduleEntity.contentEntity == null); } @Override protected LiveData<ApiResponse<ContentResponse>> createCall() { return remoteDataSource.getContent(moduleId); } @Override protected void saveCallResult(ContentResponse contentResponse) { localDataSource.updateContent(contentResponse.getContent(), moduleId); } }.asLiveData(); } private  AcademyRepository(@NonNull RemoteDataSource remoteDataSource, @NonNull LocalDataSource localDataSource, AppExecutors appExecutors); static AcademyRepository getInstance(RemoteDataSource remoteData, LocalDataSource localDataSource, AppExecutors appExecutors); @Override LiveData<Resource<List<CourseEntity>>> getAllCourses(); @Override LiveData<List<CourseEntity>> getBookmarkedCourses(); @Override LiveData<Resource<CourseWithModule>> getCourseWithModules(final String courseId); @Override LiveData<Resource<List<ModuleEntity>>> getAllModulesByCourse(String courseId); @Override LiveData<Resource<ModuleEntity>> getContent(String moduleId); @Override void setCourseBookmark(CourseEntity course, boolean state); @Override void setReadModule(ModuleEntity module);  }
@Test public void getContent() { doAnswer(invocation -> { ((RemoteDataSource.LoadModulesCallback) invocation.getArguments()[1]) .onAllModulesReceived(moduleResponses); return null; }).when(remote).getModules(eq(courseId), any(RemoteDataSource.LoadModulesCallback.class)); doAnswer(invocation -> { ((RemoteDataSource.LoadContentCallback) invocation.getArguments()[1]) .onContentReceived(content); return null; }).when(remote).getContent(eq(moduleId), any(RemoteDataSource.LoadContentCallback.class)); ModuleEntity courseEntitiesContent = LiveDataTestUtil.getValue(academyRepository.getContent(courseId, moduleId)); verify(remote) .getModules(eq(courseId), any(RemoteDataSource.LoadModulesCallback.class)); verify(remote) .getContent(eq(moduleId), any(RemoteDataSource.LoadContentCallback.class)); assertNotNull(courseEntitiesContent); assertNotNull(courseEntitiesContent.contentEntity); assertNotNull(courseEntitiesContent.contentEntity.getContent()); assertEquals(content.getContent(), courseEntitiesContent.contentEntity.getContent()); }