CourseReaderViewModel extends ViewModel { public LiveData<List<ModuleEntity>> getModules() { return academyRepository.getAllModulesByCourse(courseId); } CourseReaderViewModel(AcademyRepository mAcademyRepository); void setSelectedCourse(String courseId); void setSelectedModule(String moduleId); LiveData<List<ModuleEntity>> getModules(); LiveData<ModuleEntity> getSelectedModule();  }
@Test public void getModules() { when(academyRepository.getAllModulesByCourse(courseId)).thenReturn(dummyModules); List<ModuleEntity> moduleEntities = viewModel.getModules(); verify(academyRepository).getAllModulesByCourse(courseId); assertNotNull(moduleEntities); assertEquals(7, moduleEntities.size()); }
@Test public void getModules() { MutableLiveData<List<ModuleEntity>> modules = new MutableLiveData<>(); modules.setValue(dummyModules); when(academyRepository.getAllModulesByCourse(courseId)).thenReturn(modules); List<ModuleEntity> moduleEntities = viewModel.getModules().getValue(); verify(academyRepository).getAllModulesByCourse(courseId); assertNotNull(moduleEntities); assertEquals(7, moduleEntities.size()); viewModel.getModules().observeForever(modulesObserver); verify(modulesObserver).onChanged(dummyModules); }