@Test public void testGetStudents() { List<String> testStudents = Arrays.asList("Baldo", "Mero"); when(repository.queryStudents()).thenReturn(testStudents); List<String> students = viewModel.getStudents(true); Mockito.verify(repository).queryStudents(); assertThat(students, contains("Baldo", "Mero")); }
List<String> getStudents(boolean forceLoad) { if (students == null || forceLoad) { students = repository.queryStudents(); } return students; }
MainActivityViewModel extends ViewModel { List<String> getStudents(boolean forceLoad) { if (students == null || forceLoad) { students = repository.queryStudents(); } return students; } }
MainActivityViewModel extends ViewModel { List<String> getStudents(boolean forceLoad) { if (students == null || forceLoad) { students = repository.queryStudents(); } return students; } MainActivityViewModel(@NonNull Repository repository); }
MainActivityViewModel extends ViewModel { List<String> getStudents(boolean forceLoad) { if (students == null || forceLoad) { students = repository.queryStudents(); } return students; } MainActivityViewModel(@NonNull Repository repository);  }
MainActivityViewModel extends ViewModel { List<String> getStudents(boolean forceLoad) { if (students == null || forceLoad) { students = repository.queryStudents(); } return students; } MainActivityViewModel(@NonNull Repository repository);   }