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