@Test public void getContent() { when(remote.getModules(courseId)).thenReturn(moduleResponses); when(remote.getContent(moduleId)).thenReturn(content); ModuleEntity resultModule = academyRepository.getContent(courseId, moduleId); verify(remote).getContent(moduleId); assertNotNull(resultModule); assertEquals(content.getContent(), resultModule.contentEntity.getContent()); }
@Override public LiveData<ModuleEntity> getContent(String courseId, String moduleId) { MutableLiveData<ModuleEntity> moduleResult = new MutableLiveData<>(); remoteDataSource.getModules(courseId, moduleResponses -> { ModuleEntity module; for (ModuleResponse response : moduleResponses) { if (response.getModuleId().equals(moduleId)) { module = new ModuleEntity(response.getModuleId(), response.getCourseId(), response.getTitle(), response.getPosition(), false); remoteDataSource.getContent(moduleId, contentResponse -> { module.contentEntity = new ContentEntity(contentResponse.getContent()); moduleResult.postValue(module); }); break; } } }); return moduleResult; }
AcademyRepository implements AcademyDataSource { @Override public LiveData<ModuleEntity> getContent(String courseId, String moduleId) { MutableLiveData<ModuleEntity> moduleResult = new MutableLiveData<>(); remoteDataSource.getModules(courseId, moduleResponses -> { ModuleEntity module; for (ModuleResponse response : moduleResponses) { if (response.getModuleId().equals(moduleId)) { module = new ModuleEntity(response.getModuleId(), response.getCourseId(), response.getTitle(), response.getPosition(), false); remoteDataSource.getContent(moduleId, contentResponse -> { module.contentEntity = new ContentEntity(contentResponse.getContent()); moduleResult.postValue(module); }); break; } } }); return moduleResult; } }
AcademyRepository implements AcademyDataSource { @Override public LiveData<ModuleEntity> getContent(String courseId, String moduleId) { MutableLiveData<ModuleEntity> moduleResult = new MutableLiveData<>(); remoteDataSource.getModules(courseId, moduleResponses -> { ModuleEntity module; for (ModuleResponse response : moduleResponses) { if (response.getModuleId().equals(moduleId)) { module = new ModuleEntity(response.getModuleId(), response.getCourseId(), response.getTitle(), response.getPosition(), false); remoteDataSource.getContent(moduleId, contentResponse -> { module.contentEntity = new ContentEntity(contentResponse.getContent()); moduleResult.postValue(module); }); break; } } }); return moduleResult; } private  AcademyRepository(@NonNull RemoteDataSource remoteDataSource); }
AcademyRepository implements AcademyDataSource { @Override public LiveData<ModuleEntity> getContent(String courseId, String moduleId) { MutableLiveData<ModuleEntity> moduleResult = new MutableLiveData<>(); remoteDataSource.getModules(courseId, moduleResponses -> { ModuleEntity module; for (ModuleResponse response : moduleResponses) { if (response.getModuleId().equals(moduleId)) { module = new ModuleEntity(response.getModuleId(), response.getCourseId(), response.getTitle(), response.getPosition(), false); remoteDataSource.getContent(moduleId, contentResponse -> { module.contentEntity = new ContentEntity(contentResponse.getContent()); moduleResult.postValue(module); }); break; } } }); return moduleResult; } 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<ModuleEntity> getContent(String courseId, String moduleId) { MutableLiveData<ModuleEntity> moduleResult = new MutableLiveData<>(); remoteDataSource.getModules(courseId, moduleResponses -> { ModuleEntity module; for (ModuleResponse response : moduleResponses) { if (response.getModuleId().equals(moduleId)) { module = new ModuleEntity(response.getModuleId(), response.getCourseId(), response.getTitle(), response.getPosition(), false); remoteDataSource.getContent(moduleId, contentResponse -> { module.contentEntity = new ContentEntity(contentResponse.getContent()); moduleResult.postValue(module); }); break; } } }); return moduleResult; } 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);  }