@Test public void getCourseWithModules() { when(remote.getAllCourses()).thenReturn(courseResponses); CourseEntity resultCourse = academyRepository.getCourseWithModules(courseId); verify(remote).getAllCourses(); assertNotNull(resultCourse); assertEquals(courseResponses.get(0).getTitle(), resultCourse.getTitle()); }
@Override public LiveData<CourseEntity> getCourseWithModules(final String courseId) { MutableLiveData<CourseEntity> courseResult = new MutableLiveData<>(); remoteDataSource.getAllCourses(courseResponses -> { CourseEntity course = null; for (CourseResponse response : courseResponses) { if (response.getId().equals(courseId)) { course = new CourseEntity(response.getId(), response.getTitle(), response.getDescription(), response.getDate(), false, response.getImagePath()); } } courseResult.postValue(course); }); return courseResult; }
AcademyRepository implements AcademyDataSource { @Override public LiveData<CourseEntity> getCourseWithModules(final String courseId) { MutableLiveData<CourseEntity> courseResult = new MutableLiveData<>(); remoteDataSource.getAllCourses(courseResponses -> { CourseEntity course = null; for (CourseResponse response : courseResponses) { if (response.getId().equals(courseId)) { course = new CourseEntity(response.getId(), response.getTitle(), response.getDescription(), response.getDate(), false, response.getImagePath()); } } courseResult.postValue(course); }); return courseResult; } }
AcademyRepository implements AcademyDataSource { @Override public LiveData<CourseEntity> getCourseWithModules(final String courseId) { MutableLiveData<CourseEntity> courseResult = new MutableLiveData<>(); remoteDataSource.getAllCourses(courseResponses -> { CourseEntity course = null; for (CourseResponse response : courseResponses) { if (response.getId().equals(courseId)) { course = new CourseEntity(response.getId(), response.getTitle(), response.getDescription(), response.getDate(), false, response.getImagePath()); } } courseResult.postValue(course); }); return courseResult; } private  AcademyRepository(@NonNull RemoteDataSource remoteDataSource); }
AcademyRepository implements AcademyDataSource { @Override public LiveData<CourseEntity> getCourseWithModules(final String courseId) { MutableLiveData<CourseEntity> courseResult = new MutableLiveData<>(); remoteDataSource.getAllCourses(courseResponses -> { CourseEntity course = null; for (CourseResponse response : courseResponses) { if (response.getId().equals(courseId)) { course = new CourseEntity(response.getId(), response.getTitle(), response.getDescription(), response.getDate(), false, response.getImagePath()); } } courseResult.postValue(course); }); return courseResult; } private  AcademyRepository(@NonNull RemoteDataSource remoteDataSource); static AcademyRepository getInstance(RemoteDataSource remoteData); @Override LiveData<List<CourseEntity>> getAllCourses(); @Override LiveData<List<CourseEntity>> getBookmarkedCourses(); @Override LiveData<CourseEntity> getCourseWithModules(final String courseId); @Override LiveData<List<ModuleEntity>> getAllModulesByCourse(String courseId); @Override LiveData<ModuleEntity> getContent(String courseId, String moduleId); }
AcademyRepository implements AcademyDataSource { @Override public LiveData<CourseEntity> getCourseWithModules(final String courseId) { MutableLiveData<CourseEntity> courseResult = new MutableLiveData<>(); remoteDataSource.getAllCourses(courseResponses -> { CourseEntity course = null; for (CourseResponse response : courseResponses) { if (response.getId().equals(courseId)) { course = new CourseEntity(response.getId(), response.getTitle(), response.getDescription(), response.getDate(), false, response.getImagePath()); } } courseResult.postValue(course); }); return courseResult; } private  AcademyRepository(@NonNull RemoteDataSource remoteDataSource); static AcademyRepository getInstance(RemoteDataSource remoteData); @Override LiveData<List<CourseEntity>> getAllCourses(); @Override LiveData<List<CourseEntity>> getBookmarkedCourses(); @Override LiveData<CourseEntity> getCourseWithModules(final String courseId); @Override LiveData<List<ModuleEntity>> getAllModulesByCourse(String courseId); @Override LiveData<ModuleEntity> getContent(String courseId, String moduleId);  }