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<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 getContent() { MutableLiveData<ModuleEntity> dummyEntity = new MutableLiveData<>(); dummyEntity.setValue(DataDummy.generateDummyModuleWithContent(moduleId)); when(local.getModuleWithContent(courseId)).thenReturn(dummyEntity); Resource<ModuleEntity> courseEntitiesContent = LiveDataTestUtil.getValue(academyRepository.getContent(courseId)); verify(local).getModuleWithContent(courseId); assertNotNull(courseEntitiesContent); assertNotNull(courseEntitiesContent.data.contentEntity); assertNotNull(courseEntitiesContent.data.contentEntity.getContent()); assertEquals(content.getContent(), courseEntitiesContent.data.contentEntity.getContent()); }