BookmarkViewModel extends ViewModel { public LiveData<List<CourseEntity>> getBookmarks() { return academyRepository.getBookmarkedCourses(); } BookmarkViewModel(AcademyRepository mAcademyRepository); LiveData<List<CourseEntity>> getBookmarks();  }
@Test public void getBookmark() { when(academyRepository.getBookmarkedCourses()).thenReturn(DataDummy.generateDummyCourses()); List<CourseEntity> courseEntities = viewModel.getBookmarks(); verify(academyRepository).getBookmarkedCourses(); assertNotNull(courseEntities); assertEquals(5, courseEntities.size()); }
@Test public void getBookmark() { ArrayList<CourseEntity> dummyCourses = DataDummy.generateDummyCourses(); MutableLiveData<List<CourseEntity>> courses = new MutableLiveData<>(); courses.setValue(dummyCourses); when(academyRepository.getBookmarkedCourses()).thenReturn(courses); List<CourseEntity> courseEntities = viewModel.getBookmarks().getValue(); verify(academyRepository).getBookmarkedCourses(); assertNotNull(courseEntities); assertEquals(5, courseEntities.size()); viewModel.getBookmarks().observeForever(observer); verify(observer).onChanged(dummyCourses); }