@Test public void getAllCourses() { when(remote.getAllCourses()).thenReturn(courseResponses); ArrayList<CourseEntity> courseEntities = academyRepository.getAllCourses(); verify(remote).getAllCourses(); assertNotNull(courseEntities); assertEquals(courseResponses.size(), courseEntities.size()); }
@Override public LiveData<List<CourseEntity>> getAllCourses() { MutableLiveData<List<CourseEntity>> courseResults = new MutableLiveData<>(); remoteDataSource.getAllCourses(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); } courseResults.postValue(courseList); }); return courseResults; }
AcademyRepository implements AcademyDataSource { @Override public LiveData<List<CourseEntity>> getAllCourses() { MutableLiveData<List<CourseEntity>> courseResults = new MutableLiveData<>(); remoteDataSource.getAllCourses(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); } courseResults.postValue(courseList); }); return courseResults; } }
AcademyRepository implements AcademyDataSource { @Override public LiveData<List<CourseEntity>> getAllCourses() { MutableLiveData<List<CourseEntity>> courseResults = new MutableLiveData<>(); remoteDataSource.getAllCourses(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); } courseResults.postValue(courseList); }); return courseResults; } private  AcademyRepository(@NonNull RemoteDataSource remoteDataSource); }
AcademyRepository implements AcademyDataSource { @Override public LiveData<List<CourseEntity>> getAllCourses() { MutableLiveData<List<CourseEntity>> courseResults = new MutableLiveData<>(); remoteDataSource.getAllCourses(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); } courseResults.postValue(courseList); }); return courseResults; } 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<List<CourseEntity>> getAllCourses() { MutableLiveData<List<CourseEntity>> courseResults = new MutableLiveData<>(); remoteDataSource.getAllCourses(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); } courseResults.postValue(courseList); }); return courseResults; } 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);  }