AcademyViewModel extends ViewModel { public LiveData<Resource<List<CourseEntity>>> getCourses() { return academyRepository.getAllCourses(); } AcademyViewModel(AcademyRepository mAcademyRepository); LiveData<Resource<List<CourseEntity>>> getCourses();  }
@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); }