CorrespondingHolidayManager { protected List<Holiday> getCorrespondingHolidays(List<Holiday> holidays, LocalDate hiringDate, int yearOfCalculation) { List<Holiday> holidaysFromCalculationYear = holidays.stream() .filter(holiday -> parseDate(holiday.getDate()).getYear() == yearOfCalculation) .collect(Collectors.toList()); if (isHiringYearThisYear(yearOfCalculation, hiringDate)) { removeCompensationDays(holidaysFromCalculationYear, yearOfCalculation, hiringDate); } return holidaysFromCalculationYear; } protected  CorrespondingHolidayManager(); static CorrespondingHolidayManager getDefault(); List<Holiday> calculateCorrespondingHolidays(Calendar calMin, Calendar calMax, List<Holiday> allHolidays,
			Date hiringDate);  }
@Test public void shouldNotRemoveCompensationDaysIfHiredPreviously() { List<Holiday> holidays = this.getListOfCompensationDays(1); LocalDate hiringDate = new GregorianCalendar(2018, Calendar.JANUARY, 10).getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); List<Holiday> result = sut.getCorrespondingHolidays(holidays, hiringDate, 2019); assertThat(result, is(not(empty()))); }
@Test public void shouldConsiderWeekendsAndHolidaysForCalculation() { List<Holiday> holidays = this.getListOfCompensationDays(5); Holiday newYear2019 = new Holiday(); newYear2019.setCompensation(false); newYear2019.setDate(new GregorianCalendar(2019, Calendar.JANUARY, 1).getTime()); List<Holiday> january2019 = Arrays.asList(newYear2019); doReturn(january2019).when(holidayManager).getAllEntities(any(), any()); LocalDate hiringDate = new GregorianCalendar(2019, Calendar.JANUARY, 8).getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); List<Holiday> result = sut.getCorrespondingHolidays(holidays, hiringDate, 2019); assertThat(result.size(), is(1)); }
@Test public void shouldRemoveCompensationDaysInOrder() { List<Holiday> holidays = this.getListOfCompensationDays(2); LocalDate hiringDate = new GregorianCalendar(2019, Calendar.JANUARY, 3).getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); Holiday newYear2019 = new Holiday(); newYear2019.setId(6); newYear2019.setCompensation(false); newYear2019.setDate(new GregorianCalendar(2019, Calendar.JANUARY, 1).getTime()); List<Holiday> january2019 = Arrays.asList(newYear2019); doReturn(january2019).when(holidayManager).getAllEntities(any(), any()); List<Holiday> result = sut.getCorrespondingHolidays(holidays, hiringDate, 2019); assertThat(result, is(not(empty()))); assertThat(result.get(0), is(holidays.get(holidays.size()-1))); assertThat(result.size(), is(1)); }
@Test public void shouldCheckFirstDaysOfJanuaryForHolidays() { LocalDate hiringDate = new GregorianCalendar(2019, Calendar.JANUARY, 10).getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); Holiday newYear2019 = new Holiday(); newYear2019.setId(2); newYear2019.setCompensation(false); newYear2019.setDate(new GregorianCalendar(2019, Calendar.JANUARY, 1).getTime()); List<Holiday> january2019 = Arrays.asList(newYear2019); Date januaryMin = new GregorianCalendar(2019, Calendar.JANUARY, 01, 0, 0).getTime(); Date januaryMax = new GregorianCalendar(2019, Calendar.JANUARY, 31, 23, 59).getTime(); HolidaySearch holidaySearch = new HolidaySearch(); holidaySearch.setStartDate(januaryMin); holidaySearch.setEndDate(januaryMax); List<Holiday> result = sut.getCorrespondingHolidays(january2019, hiringDate, 2019); verify(holidayManager).getAllEntities(holidaySearch, null); }