CourseProcessor implements ItemProcessor<Course, Course> { public Course process(Course course) throws Exception { if (!CampusUtils.addIfNotAlreadyProcessed(processedIdsSet, course.getId())) { LOG.debug("This is a duplicate of this course [" + course.getId() + "]"); return null; } course.setModifiedDate(new Date()); if (course.getTitle().contains(CampusUtils.SEMICOLON_REPLACEMENT)) { course.setTitle(StringUtils.replace(course.getTitle(), CampusUtils.SEMICOLON_REPLACEMENT, CampusUtils.SEMICOLON)); } String shortSemester = buildShortSemester(course.getSemester()); if (shortSemester != null) { course.setShortSemester(shortSemester); course.setTitle(shortSemester.concat(WHITESPACE).concat(course.getTitle())); } if (enabledOrgs.isEmpty()) { if (course.getIpz().equalsIgnoreCase("X")) { course.setEnabled("1"); } } else if (enabledOrgs.contains(course.getOrg1()) || enabledOrgs.contains(course.getOrg2()) || enabledOrgs.contains(course.getOrg3()) || enabledOrgs.contains(course.getOrg4()) || enabledOrgs.contains(course.getOrg5())) { course.setEnabled("1"); } return course; }  @PostConstruct void init(); @PreDestroy void cleanUp(); void setSemesterMap(Map<String, String> semesterMap); Course process(Course course);  }
@Test public void process_Duplicate() throws Exception { course.setId(100L); course.setTitle("Title"); course.setSemester(null); course.setEnabled("0"); Course resultCourse = courseProcessor.process(course); assertEquals(resultCourse, course); Course duplicateCourse = courseProcessor.process(course); assertNull(duplicateCourse); }
@Test public void process_semesterIsNull() throws Exception { course.setId(100L); course.setTitle("Title"); course.setSemester(null); course = courseProcessor.process(course); assertEquals(course.getTitle(), "Title"); }
@Test public void process_semesterIsNotNull() throws Exception { course.setId(200L); course.setTitle("Title"); course.setSemester("Herbstsemester 2012"); course = courseProcessor.process(course); assertEquals(course.getTitle(), "12HS Title"); course.setId(300L); course.setTitle("Title"); course.setSemester("Frühjahrssemester 2013"); course = courseProcessor.process(course); assertEquals(course.getTitle(), "13FS Title"); }