@Test public void projectHasCorrectExerciseSet() { Project project = mock(Project.class); Course course = new Course("foo"); course.setId(1); List<Exercise> exercises = new ArrayList<Exercise>(); exercises.add(new Exercise("foo", "bar")); exercises.add(new Exercise("baz", "qux")); exercises.get(1).setChecksum("1234"); exercises.get(1).setUpdateAvailable(false); exercises.get(1).setCourse(course); exercises.get(1).setProject(project); course.setExercises(exercises); List<Exercise> serverExercises = new ArrayList<Exercise>(); serverExercises.add(new Exercise("baz", "qux")); when(server.getExercises("1")).thenReturn(serverExercises); when(projectDAO.getProjectByExercise(exercises.get(1))).thenReturn(project); updater.updateExercises(course); verify(project, times(1)).setExercise(serverExercises.get(0)); }
public void updateExercises(Course course) { if (course == null) { throw new UserVisibleException("Remember to select your course from TMC -> Settings"); } List<Exercise> oldExercises = course.getExercises(); List<Exercise> newExercises = server.getExercises(course.getId() + ""); for (Exercise newExercise : newExercises) { Exercise oldExercise = findEqualExercise(oldExercises, newExercise); if (oldExercise != null) { updateExercise(oldExercise, newExercise); } } course.setExercises(newExercises); }
Updater { public void updateExercises(Course course) { if (course == null) { throw new UserVisibleException("Remember to select your course from TMC -> Settings"); } List<Exercise> oldExercises = course.getExercises(); List<Exercise> newExercises = server.getExercises(course.getId() + ""); for (Exercise newExercise : newExercises) { Exercise oldExercise = findEqualExercise(oldExercises, newExercise); if (oldExercise != null) { updateExercise(oldExercise, newExercise); } } course.setExercises(newExercises); } }
Updater { public void updateExercises(Course course) { if (course == null) { throw new UserVisibleException("Remember to select your course from TMC -> Settings"); } List<Exercise> oldExercises = course.getExercises(); List<Exercise> newExercises = server.getExercises(course.getId() + ""); for (Exercise newExercise : newExercises) { Exercise oldExercise = findEqualExercise(oldExercises, newExercise); if (oldExercise != null) { updateExercise(oldExercise, newExercise); } } course.setExercises(newExercises); } Updater(ServerManager server, CourseDAO courseDAO, ProjectDAO projectDAO); }
Updater { public void updateExercises(Course course) { if (course == null) { throw new UserVisibleException("Remember to select your course from TMC -> Settings"); } List<Exercise> oldExercises = course.getExercises(); List<Exercise> newExercises = server.getExercises(course.getId() + ""); for (Exercise newExercise : newExercises) { Exercise oldExercise = findEqualExercise(oldExercises, newExercise); if (oldExercise != null) { updateExercise(oldExercise, newExercise); } } course.setExercises(newExercises); } Updater(ServerManager server, CourseDAO courseDAO, ProjectDAO projectDAO); void updateCourses(); void updateExercises(Course course); }
Updater { public void updateExercises(Course course) { if (course == null) { throw new UserVisibleException("Remember to select your course from TMC -> Settings"); } List<Exercise> oldExercises = course.getExercises(); List<Exercise> newExercises = server.getExercises(course.getId() + ""); for (Exercise newExercise : newExercises) { Exercise oldExercise = findEqualExercise(oldExercises, newExercise); if (oldExercise != null) { updateExercise(oldExercise, newExercise); } } course.setExercises(newExercises); } Updater(ServerManager server, CourseDAO courseDAO, ProjectDAO projectDAO); void updateCourses(); void updateExercises(Course course);  }