DetailCourseViewModel extends ViewModel { public LiveData<CourseEntity> getCourse() { return academyRepository.getCourseWithModules(courseId); } DetailCourseViewModel(AcademyRepository mAcademyRepository); void setSelectedCourse(String courseId); LiveData<CourseEntity> getCourse(); LiveData<List<ModuleEntity>> getModules();  }
@Test public void getCourse() { when(academyRepository.getCourseWithModules(courseId)).thenReturn(dummyCourse); CourseEntity courseEntity = viewModel.getCourse(); verify(academyRepository).getCourseWithModules(courseId); assertNotNull(courseEntity); assertEquals(dummyCourse.getCourseId(), courseEntity.getCourseId()); assertEquals(dummyCourse.getDeadline(), courseEntity.getDeadline()); assertEquals(dummyCourse.getDescription(), courseEntity.getDescription()); assertEquals(dummyCourse.getImagePath(), courseEntity.getImagePath()); assertEquals(dummyCourse.getTitle(), courseEntity.getTitle()); }
@Test public void getCourse() { MutableLiveData<CourseEntity> course = new MutableLiveData<>(); course.setValue(dummyCourse); when(academyRepository.getCourseWithModules(courseId)).thenReturn(course); CourseEntity courseEntity = viewModel.getCourse().getValue(); verify(academyRepository).getCourseWithModules(courseId); assertNotNull(courseEntity); assertEquals(dummyCourse.getCourseId(), courseEntity.getCourseId()); assertEquals(dummyCourse.getDeadline(), courseEntity.getDeadline()); assertEquals(dummyCourse.getDescription(), courseEntity.getDescription()); assertEquals(dummyCourse.getImagePath(), courseEntity.getImagePath()); assertEquals(dummyCourse.getTitle(), courseEntity.getTitle()); viewModel.getCourse().observeForever(courseObserver); verify(courseObserver).onChanged(dummyCourse); }