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