Skip to content

Commit

Permalink
include empty PublicHolidayCalendar for FederalState.NONE
Browse files Browse the repository at this point in the history
  • Loading branch information
bseber committed Dec 28, 2023
1 parent b393a4e commit 50aedc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ public Map<FederalState, PublicHolidayCalendar> getPublicHolidays(LocalDate from
final Map<FederalState, PublicHolidayCalendar> calendar = new EnumMap<>(FederalState.class);

for (FederalState federalState : federalStates) {
if (federalState != FederalState.NONE) {
final Map<LocalDate, List<PublicHoliday>> holidays;
if (federalState == FederalState.NONE) {
holidays = Map.of();
} else {
final HolidayManager holidayManager = holidayManagers.get(federalState.getCountry());
final Map<LocalDate, List<PublicHoliday>> holidays = holidayManager.getHolidays(from, to, federalState.getCodes())
holidays = holidayManager.getHolidays(from, to, federalState.getCodes())
.stream()
.map(holiday -> new PublicHoliday(holiday.getDate(), holiday::getDescription))
.collect(groupingBy(PublicHoliday::date));

calendar.put(federalState, new PublicHolidayCalendar(federalState, holidays));
}
calendar.put(federalState, new PublicHolidayCalendar(federalState, holidays));
}

return calendar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ void ensureGetPublicHolidays() {

final Map<FederalState, PublicHolidayCalendar> actual = sut.getPublicHolidays(from, toExclusive, federalStates);

assertThat(actual).hasSize(1);
assertThat(actual).hasSize(2);
assertThat(actual).hasEntrySatisfying(NONE, publicHolidayCalendar -> {
assertThat(publicHolidayCalendar.federalState()).isEqualTo(NONE);
assertThat(publicHolidayCalendar.publicHolidays()).isEmpty();
});
assertThat(actual).hasEntrySatisfying(GERMANY_BADEN_WUERTTEMBERG, publicHolidayCalendar -> {
assertThat(publicHolidayCalendar.federalState()).isEqualTo(GERMANY_BADEN_WUERTTEMBERG);
assertThat(publicHolidayCalendar.publicHolidays()).satisfies(map -> {
Expand Down

0 comments on commit 50aedc3

Please sign in to comment.