CourseReaderViewModel extends ViewModel { public LiveData<ModuleEntity> getSelectedModule() { return academyRepository.getContent(courseId, moduleId); } CourseReaderViewModel(AcademyRepository mAcademyRepository); void setSelectedCourse(String courseId); void setSelectedModule(String moduleId); LiveData<List<ModuleEntity>> getModules(); LiveData<ModuleEntity> getSelectedModule();  }
@Test public void getSelectedModule() { MutableLiveData<ModuleEntity> module = new MutableLiveData<>(); module.setValue(dummyModules.get(0)); when(academyRepository.getContent(courseId, moduleId)).thenReturn(module); ModuleEntity moduleEntity = viewModel.getSelectedModule().getValue(); verify(academyRepository).getContent(courseId, moduleId); assertNotNull(moduleEntity); ContentEntity contentEntity = moduleEntity.contentEntity; assertNotNull(contentEntity); String content = contentEntity.getContent(); assertNotNull(content); assertEquals(content, dummyModules.get(0).contentEntity.getContent()); viewModel.getSelectedModule().observeForever(moduleObserver); verify(moduleObserver).onChanged(dummyModules.get(0)); }
@Test public void getSelectedModule() { when(academyRepository.getContent(courseId, moduleId)).thenReturn(dummyModules.get(0)); ModuleEntity moduleEntity = viewModel.getSelectedModule(); verify(academyRepository).getContent(courseId, moduleId); assertNotNull(moduleEntity); ContentEntity contentEntity = moduleEntity.contentEntity; assertNotNull(contentEntity); String content = contentEntity.getContent(); assertNotNull(content); assertEquals(content, dummyModules.get(0).contentEntity.getContent()); }