CorrespondingHolidayManager { public List<Holiday> calculateCorrespondingHolidays(Calendar calMin, Calendar calMax, List<Holiday> allHolidays, Date hiringDate) { List<Holiday> correspondingHolidays = new ArrayList<Holiday>(); if (calMax.get(Calendar.YEAR) - calMin.get(Calendar.YEAR) > 0) { for (int year = calMin.get(Calendar.YEAR); year <= calMax.get(Calendar.YEAR); year++) { correspondingHolidays = Stream .concat(getCorrespondingHolidays(allHolidays, parseDate(hiringDate), year).stream(), correspondingHolidays.stream()) .collect(Collectors.toList()); } } else { correspondingHolidays = getCorrespondingHolidays(allHolidays, parseDate(hiringDate), calMax.get(Calendar.YEAR)); } return correspondingHolidays; } protected  CorrespondingHolidayManager(); static CorrespondingHolidayManager getDefault(); List<Holiday> calculateCorrespondingHolidays(Calendar calMin, Calendar calMax, List<Holiday> allHolidays,
			Date hiringDate);  }
@Test public void shouldRemoveCompensationDaysIfHiredLater() { List<Holiday> holidays = this.getListOfCompensationDays(1); Calendar calMin = new GregorianCalendar(2019, Calendar.JANUARY, 1); Calendar calMax = new GregorianCalendar(2019, Calendar.DECEMBER, 31); Date hiringDate = new GregorianCalendar(2019, Calendar.JANUARY, 10).getTime(); 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()); List<Holiday> result = sut.calculateCorrespondingHolidays(calMin, calMax, holidays, hiringDate); assertThat(result, is(empty())); }
@Test public void shouldReturnHolidaysFromSeveralYears() { List<Holiday> holidays = this.getListOfCompensationDays(3); Holiday newYear2018 = new Holiday(); newYear2018.setId(4); newYear2018.setCompensation(false); newYear2018.setDate(new GregorianCalendar(2018, Calendar.JANUARY, 1).getTime()); List<Holiday> january2018 = Arrays.asList(newYear2018); doReturn(january2018).when(holidayManager).getAllEntities(any(), any()); Date hiringDate = new GregorianCalendar(2018, Calendar.JANUARY, 2).getTime(); Calendar calMin = new GregorianCalendar(2018, Calendar.DECEMBER, 1); Calendar calMax = new GregorianCalendar(2019, Calendar.FEBRUARY, 1); List<Holiday> result = sut.calculateCorrespondingHolidays(calMin, calMax, holidays, hiringDate); assertThat(result.size(), is(3)); }
@Test public void shouldReturnHolidaysFromSeveralYearsConsideringHiring() { List<Holiday> holidays = this.getListOfCompensationDays(3); Holiday newYear2018 = new Holiday(); newYear2018.setId(4); newYear2018.setCompensation(false); newYear2018.setDate(new GregorianCalendar(2018, Calendar.JANUARY, 1).getTime()); List<Holiday> january2018 = Arrays.asList(newYear2018); doReturn(january2018).when(holidayManager).getAllEntities(any(), any()); Date hiringDate = new GregorianCalendar(2019, Calendar.JANUARY, 3).getTime(); Calendar calMin = new GregorianCalendar(2018, Calendar.DECEMBER, 1); Calendar calMax = new GregorianCalendar(2019, Calendar.FEBRUARY, 1); List<Holiday> result = sut.calculateCorrespondingHolidays(calMin, calMax, holidays, hiringDate); assertThat(result.size(), is(1)); }