@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())); }
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; }
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; } }
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(); }
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); }
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);  }