MoodleViewModel extends AndroidViewModel { public void setDisplayPastAssignments(boolean display) { SharedPreferences settings = getApplication().getSharedPreferences(MOODLE_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(DISPLAY_PAST_ASSIGNMENTS_PREF, display); editor.apply(); if (assignmentCourses != null) { RemoteResource<List<MoodleAssignmentCourse>> remoteResource = assignmentCourses.getValue(); if (remoteResource != null) setFilteredAssignmentCourses(remoteResource); } } MoodleViewModel(Application application, MoodleRepository moodleRepository); boolean isShowCaseHasBeenDisplayed(); void setShowCaseHasBeenDisplayed(boolean display); LiveData<RemoteResource<List<MoodleCourse>>> getCourses(); LiveData<RemoteResource<List<MoodleAssignmentCourse>>> getAssignmentCourses(); LiveData<RemoteResource<MoodleAssignmentSubmission>> getAssignmentSubmission(int assignId); void setDisplayPastAssignments(boolean display); boolean isDisplayPastAssignments(); void setAssignmentsSortIndex(int index); int getAssignmentsSortIndex(); Comparator<MoodleAssignment> getAssignmentsSortComparator(); void selectAssignment(MoodleAssignment selectedAssignment); LiveData<MoodleAssignment> getSelectedAssignment(); static final int SORT_BY_DATE; static final int SORT_ALPHA; }
@Test public void setDisplayPastAssignments() { createMockSharedPreferences(); viewModel.setDisplayPastAssignments(true); verify(editor).putBoolean(DISPLAY_PAST_ASSIGNMENTS_PREF, true); when(prefs.getBoolean(eq(DISPLAY_PAST_ASSIGNMENTS_PREF), anyBoolean())).thenReturn(true); assertTrue(viewModel.isDisplayPastAssignments()); reset(editor); viewModel.setDisplayPastAssignments(false); verify(editor).putBoolean(DISPLAY_PAST_ASSIGNMENTS_PREF, false); when(prefs.getBoolean(eq(DISPLAY_PAST_ASSIGNMENTS_PREF), anyBoolean())).thenReturn(false); assertFalse(viewModel.isDisplayPastAssignments()); }