AcademyRepository implements AcademyDataSource { @Override public LiveData<List<CourseEntity>> getBookmarkedCourses() { 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);  }
@Test public void getBookmarkedCourses() { when(remote.getAllCourses()).thenReturn(courseResponses); ArrayList<CourseEntity> courseEntities = academyRepository.getBookmarkedCourses(); verify(remote).getAllCourses(); assertNotNull(courseEntities); assertEquals(courseResponses.size(), courseEntities.size()); }
@Test public void getBookmarkedCourses() { doAnswer(invocation -> { ((RemoteDataSource.LoadCoursesCallback) invocation.getArguments()[0]) .onAllCoursesReceived(courseResponses); return null; }).when(remote).getAllCourses(any(RemoteDataSource.LoadCoursesCallback.class)); List<CourseEntity> courseEntities = LiveDataTestUtil.getValue(academyRepository.getBookmarkedCourses()); verify(remote).getAllCourses(any(RemoteDataSource.LoadCoursesCallback.class)); assertNotNull(courseEntities); assertEquals(courseResponses.size(), courseEntities.size()); }