private void prepareSickNoteList(Person person, int year, Model model) { List<SickNote> sickNotes = sickNoteService.getByPersonAndPeriod( person, DateUtil.getFirstDayOfYear(year), DateUtil.getLastDayOfYear(year)); List<ExtendedSickNote> extendedSickNotes = FluentIterable.from(sickNotes) .transform(input -> new ExtendedSickNote(input, calendarService)) .toSortedList( (o1, o2) -> { // show latest sick notes at first return o2.getStartDate().compareTo(o1.getStartDate()); }); BigDecimal sickDays = BigDecimal.ZERO; BigDecimal sickDaysWithAUB = BigDecimal.ZERO; BigDecimal childSickDays = BigDecimal.ZERO; BigDecimal childSickDaysWithAUB = BigDecimal.ZERO; for (SickNote sickNote : sickNotes) { if (!sickNote.isActive()) { continue; } if (sickNote.getType().equals(SickNoteType.SICK_NOTE_CHILD)) { childSickDays = childSickDays.add( calendarService.getWorkDays( DayLength.FULL, sickNote.getStartDate(), sickNote.getEndDate(), person)); if (sickNote.isAubPresent()) { BigDecimal workDays = calendarService.getWorkDays( DayLength.FULL, sickNote.getAubStartDate(), sickNote.getAubEndDate(), person); childSickDaysWithAUB = childSickDaysWithAUB.add(workDays); } } else { sickDays = sickDays.add( calendarService.getWorkDays( DayLength.FULL, sickNote.getStartDate(), sickNote.getEndDate(), person)); if (sickNote.isAubPresent()) { BigDecimal workDays = calendarService.getWorkDays( DayLength.FULL, sickNote.getAubStartDate(), sickNote.getAubEndDate(), person); sickDaysWithAUB = sickDaysWithAUB.add(workDays); } } } model.addAttribute("sickDays", sickDays); model.addAttribute("sickDaysWithAUB", sickDaysWithAUB); model.addAttribute("childSickDays", childSickDays); model.addAttribute("childSickDaysWithAUB", childSickDaysWithAUB); model.addAttribute("sickNotes", extendedSickNotes); }
@Before public void setUp() throws Exception { calendarService = Mockito.mock(WorkDaysService.class); sickNoteDAO = Mockito.mock(SickNoteDAO.class); sickNotes = new ArrayList<>(); Person person = TestDataCreator.createPerson(); SickNote sickNote1 = TestDataCreator.createSickNote( person, new DateMidnight(2013, DateTimeConstants.OCTOBER, 7), new DateMidnight(2013, DateTimeConstants.OCTOBER, 11), DayLength.FULL); SickNote sickNote2 = TestDataCreator.createSickNote( person, new DateMidnight(2013, DateTimeConstants.DECEMBER, 18), new DateMidnight(2014, DateTimeConstants.JANUARY, 3), DayLength.FULL); sickNotes.add(sickNote1); sickNotes.add(sickNote2); Mockito.when(sickNoteDAO.findNumberOfPersonsWithMinimumOneSickNote(2013)).thenReturn(7L); Mockito.when(sickNoteDAO.findAllActiveByYear(2013)).thenReturn(sickNotes); Mockito.when( calendarService.getWorkDays( DayLength.FULL, new DateMidnight(2013, DateTimeConstants.OCTOBER, 7), new DateMidnight(2013, DateTimeConstants.OCTOBER, 11), person)) .thenReturn(new BigDecimal("5")); Mockito.when( calendarService.getWorkDays( DayLength.FULL, new DateMidnight(2013, DateTimeConstants.DECEMBER, 18), new DateMidnight(2013, DateTimeConstants.DECEMBER, 31), person)) .thenReturn(new BigDecimal("9")); statistics = new SickNoteStatistics(2013, sickNoteDAO, calendarService); }