Skip to content

Commit

Permalink
Merge pull request #252 from focus-shift/251-improve-serbian-public-h…
Browse files Browse the repository at this point in the history
…olidays

Improve serbian public holidays
  • Loading branch information
derTobsch authored Jul 27, 2023
2 parents 6165bb4 + adfe027 commit 8642d6b
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 6 deletions.
33 changes: 27 additions & 6 deletions jollyday-core/src/main/resources/holidays/Holidays_rs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@
xmlns:tns="http://www.example.org/Holiday" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/Holiday /Holiday.xsd">
<tns:Holidays>
<tns:Fixed month="JANUARY" day="1" descriptionPropertiesKey="NEW_YEAR"/>
<tns:Fixed month="JANUARY" day="2" descriptionPropertiesKey="NEW_YEAR"/>
<tns:Fixed month="JANUARY" day="1" descriptionPropertiesKey="NEW_YEAR">
<tns:MovingCondition substitute="SUNDAY" with="NEXT" weekday="TUESDAY"/>
</tns:Fixed>
<tns:Fixed month="JANUARY" day="2" descriptionPropertiesKey="NEW_YEAR">
<tns:MovingCondition substitute="SUNDAY" with="NEXT" weekday="MONDAY"/>
</tns:Fixed>

<tns:Fixed month="JANUARY" day="7" descriptionPropertiesKey="CHRISTMAS"/>
<tns:Fixed month="FEBRUARY" day="15" descriptionPropertiesKey="CONSTITUTION_DAY"/>
<tns:Fixed month="MAY" day="1" descriptionPropertiesKey="LABOUR_DAY"/>
<tns:Fixed month="MAY" day="9" descriptionPropertiesKey="VICTORY" localizedType="UNOFFICIAL_HOLIDAY"/>
<tns:ChristianHoliday type="EASTER" descriptionPropertiesKey="christian.EASTER"/>

<tns:Fixed month="FEBRUARY" day="15" descriptionPropertiesKey="STATEHOOD">
<tns:MovingCondition substitute="SUNDAY" with="NEXT" weekday="TUESDAY"/>
</tns:Fixed>
<tns:Fixed month="FEBRUARY" day="16" descriptionPropertiesKey="STATEHOOD">
<tns:MovingCondition substitute="SUNDAY" with="NEXT" weekday="MONDAY"/>
</tns:Fixed>

<tns:Fixed month="MAY" day="1" descriptionPropertiesKey="LABOUR_DAY">
<tns:MovingCondition substitute="SUNDAY" with="NEXT" weekday="TUESDAY"/>
</tns:Fixed>
<tns:Fixed month="MAY" day="2" descriptionPropertiesKey="LABOUR_DAY">
<tns:MovingCondition substitute="SUNDAY" with="NEXT" weekday="MONDAY"/>
</tns:Fixed>

<tns:Fixed month="NOVEMBER" day="11" descriptionPropertiesKey="ARMISTICE">
<tns:MovingCondition substitute="SUNDAY" with="NEXT" weekday="MONDAY"/>
</tns:Fixed>

<tns:ChristianHoliday type="EASTER" chronology="JULIAN" descriptionPropertiesKey="christian.EASTER"/>
<tns:ChristianHoliday type="GOOD_FRIDAY" chronology="JULIAN" descriptionPropertiesKey="christian.GOOD_FRIDAY"/>
<tns:ChristianHoliday type="EASTER_MONDAY" chronology="JULIAN" descriptionPropertiesKey="christian.EASTER_MONDAY"/>
</tns:Holidays>
Expand Down
137 changes: 137 additions & 0 deletions jollyday-tests/src/test/java/de/focus_shift/tests/HolidayRSTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package de.focus_shift.tests;

import de.focus_shift.Holiday;
import de.focus_shift.HolidayManager;
import de.focus_shift.HolidayType;
import de.focus_shift.tests.base.AbstractCountryTestBase;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
import net.jqwik.time.api.constraints.YearRange;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Year;
import java.util.Set;

import static de.focus_shift.HolidayCalendar.SERBIA;
import static de.focus_shift.HolidayType.OFFICIAL_HOLIDAY;
import static de.focus_shift.ManagerParameters.create;
import static java.time.DayOfWeek.SUNDAY;
import static java.time.Month.FEBRUARY;
import static java.time.Month.JANUARY;
import static java.time.Month.MAY;
import static java.time.Month.NOVEMBER;
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
import static org.assertj.core.api.Assertions.assertThat;

class HolidayRSTest extends AbstractCountryTestBase {

@Property
void ensuresThatNewYearFirstIsConfiguredAndIfOnSundayMovesToMondayAndTuesday(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());

final LocalDate firstNewYear = LocalDate.of(year.getValue(), JANUARY, 1);
final LocalDate secondNewYear = LocalDate.of(year.getValue(), JANUARY, 2);
checkSundayMovingToNextWorkday(holidays, firstNewYear, secondNewYear, "NEW_YEAR", OFFICIAL_HOLIDAY);
}

@Property
void ensuresThatStateHoodIsConfiguredAndIfOnSundayMovesToMondayAndTuesday(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());

final LocalDate firstStateHood = LocalDate.of(year.getValue(), FEBRUARY, 15);
final LocalDate secondStateHood = LocalDate.of(year.getValue(), FEBRUARY, 16);
checkSundayMovingToNextWorkday(holidays, firstStateHood, secondStateHood, "STATEHOOD", OFFICIAL_HOLIDAY);
}

@Property
void ensuresThatLabourDayIsConfiguredAndIfOnSundayMovesToMondayAndTuesday(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());

final LocalDate firstLabourDay = LocalDate.of(year.getValue(), MAY, 1);
final LocalDate secondLabourDay = LocalDate.of(year.getValue(), MAY, 2);
checkSundayMovingToNextWorkday(holidays, firstLabourDay, secondLabourDay, "LABOUR_DAY", OFFICIAL_HOLIDAY);
}

@Property
void ensuresThatArmisticeIsConfiguredAndIfOnSundayMovesToMonday(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());

final LocalDate armistice = LocalDate.of(year.getValue(), NOVEMBER, 11);
if (isSunday(armistice)) {
assertThat(holidays)
.isNotEmpty()
.contains(new Holiday(LocalDate.of(year.getValue(), NOVEMBER, 12), "ARMISTICE", OFFICIAL_HOLIDAY));
} else {
assertThat(holidays)
.isNotEmpty()
.contains(new Holiday(LocalDate.of(year.getValue(), NOVEMBER, 11), "ARMISTICE", OFFICIAL_HOLIDAY));
}
}

@Property
void ensuresThatOrthodoxChristmasIsConfigured(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());
assertThat(holidays)
.isNotEmpty()
.contains(new Holiday(LocalDate.of(year.getValue(), JANUARY, 7), "CHRISTMAS", OFFICIAL_HOLIDAY));
}

@Property
void ensuresThatEasterIsConfigured(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());
assertThat(holidays)
.isNotEmpty()
.extracting(Holiday::getPropertiesKey)
.contains("christian.EASTER");
}

@Property
void ensuresThatGoodFridayIsConfigured(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());
assertThat(holidays)
.isNotEmpty()
.extracting(Holiday::getPropertiesKey)
.contains("christian.GOOD_FRIDAY");
}

@Property
void ensuresThatEasterMondayIsConfigured(@ForAll @YearRange Year year) {
final HolidayManager holidayManager = HolidayManager.getInstance(create(SERBIA));
final Set<Holiday> holidays = holidayManager.getHolidays(year.getValue());
assertThat(holidays)
.isNotEmpty()
.extracting(Holiday::getPropertiesKey)
.contains("christian.EASTER_MONDAY");
}

private static boolean isSunday(final LocalDate ld) {
return DayOfWeek.of(ld.get(DAY_OF_WEEK)) == SUNDAY;
}

private static void checkSundayMovingToNextWorkday(Set<Holiday> holidays, LocalDate firstDay, LocalDate secondDay, String descriptionPropertiesKey, HolidayType holidayType) {
if (isSunday(firstDay)) {
assertThat(holidays)
.isNotEmpty()
.contains(new Holiday(secondDay, descriptionPropertiesKey, holidayType))
.contains(new Holiday(firstDay.plusDays(2), descriptionPropertiesKey, holidayType));
} else if (isSunday(secondDay)) {
assertThat(holidays)
.isNotEmpty()
.contains(new Holiday(firstDay, descriptionPropertiesKey, holidayType))
.contains(new Holiday(secondDay.plusDays(1), descriptionPropertiesKey, holidayType));
} else {
assertThat(holidays)
.isNotEmpty()
.contains(new Holiday(firstDay, descriptionPropertiesKey, holidayType))
.contains(new Holiday(secondDay, descriptionPropertiesKey, holidayType));
}
}
}

0 comments on commit 8642d6b

Please sign in to comment.