AcademyRepository implements AcademyDataSource { @Override public LiveData<Resource<PagedList<CourseEntity>>> getAllCourses() { return new NetworkBoundResource<PagedList<CourseEntity>, List<CourseResponse>>(appExecutors) { @Override public LiveData<PagedList<CourseEntity>> loadFromDB() { PagedList.Config config = new PagedList.Config.Builder() .setEnablePlaceholders(false) .setInitialLoadSizeHint(4) .setPageSize(4) .build(); return new LivePagedListBuilder<>(localDataSource.getAllCourses(), config).build(); } @Override public Boolean shouldFetch(PagedList<CourseEntity> data) { return (data == null) || (data.size() == 0); } @Override public LiveData<ApiResponse<List<CourseResponse>>> createCall() { return remoteDataSource.getAllCourses(); } @Override public void saveCallResult(List<CourseResponse> courseResponses) { ArrayList<CourseEntity> courseList = new ArrayList<>(); for (CourseResponse response : courseResponses) { CourseEntity course = new CourseEntity(response.getId(), response.getTitle(), response.getDescription(), response.getDate(), false, response.getImagePath()); courseList.add(course); } localDataSource.insertCourses(courseList); } }.asLiveData(); } private  AcademyRepository(@NonNull RemoteDataSource remoteDataSource, @NonNull LocalDataSource localDataSource, AppExecutors appExecutors); static AcademyRepository getInstance(RemoteDataSource remoteData, LocalDataSource localDataSource, AppExecutors appExecutors); @Override LiveData<Resource<PagedList<CourseEntity>>> getAllCourses(); @Override LiveData<PagedList<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 getAllCourses() { MutableLiveData<List<CourseEntity>> dummyCourses = new MutableLiveData<>(); dummyCourses.setValue(DataDummy.generateDummyCourses()); when(local.getAllCourses()).thenReturn(dummyCourses); Resource<List<CourseEntity>> courseEntities = LiveDataTestUtil.getValue(academyRepository.getAllCourses()); verify(local).getAllCourses(); assertNotNull(courseEntities.data); assertEquals(courseResponses.size(), courseEntities.data.size()); }