From 2c6952b791c11a996744be2352b31f088e2aa65f Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Wed, 18 Sep 2024 21:21:18 +0200 Subject: [PATCH] Provide actual and observed holiday date --- .../de/focus_shift/jollyday/core/Holiday.java | 87 ++++++++++++++----- .../core/parser/functions/CreateHoliday.java | 14 ++- .../parser/functions/MoveDateRelative.java | 7 +- .../parser/impl/ChristianHolidayParser.java | 48 +++++----- .../core/parser/impl/DescribedDateHolder.java | 20 +++-- .../core/parser/impl/FixedParser.java | 9 +- .../impl/FixedWeekdayBetweenFixedParser.java | 2 +- .../impl/FixedWeekdayInMonthParser.java | 2 +- .../FixedWeekdayRelativeToFixedParser.java | 2 +- .../parser/impl/IslamicHolidayParser.java | 4 +- .../impl/RelativeToEasterSundayParser.java | 2 +- .../jollyday/core/spi/Holidays.java | 2 +- .../jollyday/core/HolidayTest.java | 24 ++++- .../functions/MoveDateRelativeTest.java | 32 +++---- .../parser/impl/IslamicHolidayParserTest.java | 3 + 15 files changed, 174 insertions(+), 84 deletions(-) diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/Holiday.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/Holiday.java index 6a744e607..3ce2c8f6d 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/Holiday.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/Holiday.java @@ -4,6 +4,8 @@ import java.time.LocalDate; import java.util.Locale; +import java.util.Objects; +import java.util.Optional; /** * Represents the holiday and contains the actual date and an localized @@ -14,15 +16,19 @@ public final class Holiday implements Comparable { * The calculated hashcode cached for performance. */ private int hashCode = 0; + /** * The date the holiday occurs. */ - private final LocalDate date; + private final LocalDate actualDate; + /** + * The observed date of the holiday. + */ + private final LocalDate observedDate; /** * The properties key to retrieve the description with. */ private final String propertiesKey; - /** * The type of holiday. e.g. official holiday or not. */ @@ -32,26 +38,67 @@ public final class Holiday implements Comparable { * Constructs a holiday for a date using the provided properties key to * retrieve the description with. * - * @param date a {@link LocalDate} object. + * @param actualDate a {@link LocalDate} object. * @param propertiesKey a {@link java.lang.String} object. * @param type a {@link HolidayType} object. */ - public Holiday(final LocalDate date, final String propertiesKey, final HolidayType type) { + public Holiday(final LocalDate actualDate, final String propertiesKey, final HolidayType type) { + this(actualDate, null, propertiesKey, type); + } + + /** + * Constructs a holiday for a date using the provided properties key to + * retrieve the description with. + * + * @param actualDate a {@link LocalDate} object. + * @param observedDate a {@link LocalDate} object. + * @param propertiesKey a {@link java.lang.String} object. + * @param type a {@link HolidayType} object. + */ + public Holiday(final LocalDate actualDate, final LocalDate observedDate, final String propertiesKey, final HolidayType type) { super(); this.type = type; - this.date = date; + this.actualDate = actualDate; + this.observedDate = observedDate; this.propertiesKey = propertiesKey == null ? "" : propertiesKey; } + /** + * Returns the calculated holiday date. + *

+ * If the holiday is {@link de.focus_shift.jollyday.core.spi.Movable} and the holiday was moved, then: + *

    + *
  • the observed holiday date is given
  • + *
  • otherwise, the actual holiday date
  • + *
+ * @return if holiday was moved the observed date, otherwise the actual date + */ + public LocalDate getDate() { + return Optional.ofNullable(observedDate).orElse(actualDate); + } + /** *

- * Getter for the field date. + * Returns the actual date. + *

+ * If you want the observed holiday date then use {@link #getObservedDate()} *

* - * @return the holiday date + * @return the actual holiday date */ - public LocalDate getDate() { - return date; + public LocalDate getActualDate() { + return actualDate; + } + + /** + *

+ * Getter for the field observedDate. + *

+ * + * @return the observed holiday date as optional + */ + public Optional getObservedDate() { + return Optional.ofNullable(observedDate); } /** @@ -86,31 +133,27 @@ public String getDescription(Locale locale) { @Override public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof Holiday) { - final Holiday other = (Holiday) obj; - return other.date.equals(this.date) && other.propertiesKey.equals(this.propertiesKey) && type.equals(other.type); + if (obj == null || getClass() != obj.getClass()) { + return false; } - return false; + + final Holiday holiday = (Holiday) obj; + return Objects.equals(getDate(), holiday.getDate()) && + Objects.equals(propertiesKey, holiday.propertiesKey) && + type == holiday.type; } @Override public int hashCode() { if (hashCode == 0) { - int hash = 1; - hash = hash * 31 + date.hashCode(); - hash = hash * 31 + propertiesKey.hashCode(); - hash = hash * 31 + type.hashCode(); - hashCode = hash; + hashCode = Objects.hash(getDate(), propertiesKey, type); } return hashCode; } @Override public String toString() { - return date.toString() + " (" + getDescription() + ")"; + return actualDate.toString() + " (" + getDescription() + ")"; } /** diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/CreateHoliday.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/CreateHoliday.java index 1c085ff67..4509e9ad5 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/CreateHoliday.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/CreateHoliday.java @@ -8,14 +8,20 @@ public class CreateHoliday implements Function { - private final LocalDate localDate; + private final LocalDate actualDate; + private final LocalDate observedDate; - public CreateHoliday(LocalDate localDate) { - this.localDate = localDate; + public CreateHoliday(final LocalDate actualDate) { + this(actualDate, null); + } + + public CreateHoliday(final LocalDate actualDate, final LocalDate observedDate) { + this.actualDate = actualDate; + this.observedDate = observedDate; } @Override public Holiday apply(final Described described) { - return new Holiday(localDate, described.descriptionPropertiesKey(), described.holidayType()); + return new Holiday(actualDate, observedDate, described.descriptionPropertiesKey(), described.holidayType()); } } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelative.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelative.java index 9a34fd694..fe3d0a197 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelative.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelative.java @@ -4,13 +4,14 @@ import de.focus_shift.jollyday.core.spi.Movable; import java.time.LocalDate; +import java.util.Optional; import java.util.function.Function; import static de.focus_shift.jollyday.core.spi.Movable.MovingCondition.With.NEXT; import static java.time.temporal.TemporalAdjusters.nextOrSame; import static java.time.temporal.TemporalAdjusters.previousOrSame; -public class MoveDateRelative implements Function { +public class MoveDateRelative implements Function> { private final LocalDate date; @@ -19,10 +20,10 @@ public MoveDateRelative(final LocalDate date) { } @Override - public LocalDate apply(final Movable movable) { + public Optional apply(final Movable movable) { return movable.conditions().stream() .filter(new ValidMovingCondition(date)) .map(condition -> date.with(condition.with() == NEXT ? nextOrSame(condition.weekday()) : previousOrSame(condition.weekday()))) - .findFirst().orElse(date); + .findFirst(); } } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/ChristianHolidayParser.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/ChristianHolidayParser.java index 9531dcd0d..7971b969f 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/ChristianHolidayParser.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/ChristianHolidayParser.java @@ -24,62 +24,70 @@ public class ChristianHolidayParser implements HolidayParser { public List parse(final Year year, final Holidays holidays) { return holidays.christianHolidays().stream() .filter(new ValidLimitation(year)) - .map(ch -> { - LocalDate easterSunday = new CalculateEasterSunday(year).apply(ch.chronology()); - switch (ch.type()) { + .map(christianHolidayConfiguration -> { + + final LocalDate easterSunday = new CalculateEasterSunday(year).apply(christianHolidayConfiguration.chronology()); + + final LocalDate christianHoliday; + switch (christianHolidayConfiguration.type()) { case EASTER: + christianHoliday = easterSunday; break; case CLEAN_MONDAY: case SHROVE_MONDAY: - easterSunday = easterSunday.minusDays(48); + christianHoliday = easterSunday.minusDays(48); break; case MARDI_GRAS: case CARNIVAL: - easterSunday = easterSunday.minusDays(47); + christianHoliday = easterSunday.minusDays(47); break; case ASH_WEDNESDAY: - easterSunday = easterSunday.minusDays(46); + christianHoliday = easterSunday.minusDays(46); break; case MAUNDY_THURSDAY: - easterSunday = easterSunday.minusDays(3); + christianHoliday = easterSunday.minusDays(3); break; case GOOD_FRIDAY: - easterSunday = easterSunday.minusDays(2); + christianHoliday = easterSunday.minusDays(2); break; case EASTER_SATURDAY: - easterSunday = easterSunday.minusDays(1); + christianHoliday = easterSunday.minusDays(1); break; case EASTER_MONDAY: - easterSunday = easterSunday.plusDays(1); + christianHoliday = easterSunday.plusDays(1); break; case EASTER_TUESDAY: - easterSunday = easterSunday.plusDays(2); + christianHoliday = easterSunday.plusDays(2); break; case GENERAL_PRAYER_DAY: - easterSunday = easterSunday.plusDays(26); + christianHoliday = easterSunday.plusDays(26); break; case ASCENSION_DAY: - easterSunday = easterSunday.plusDays(39); + christianHoliday = easterSunday.plusDays(39); break; case PENTECOST: case WHIT_SUNDAY: - easterSunday = easterSunday.plusDays(49); + christianHoliday = easterSunday.plusDays(49); break; case WHIT_MONDAY: case PENTECOST_MONDAY: - easterSunday = easterSunday.plusDays(50); + christianHoliday = easterSunday.plusDays(50); break; case CORPUS_CHRISTI: - easterSunday = easterSunday.plusDays(60); + christianHoliday = easterSunday.plusDays(60); break; case SACRED_HEART: - easterSunday = easterSunday.plusDays(68); + christianHoliday = easterSunday.plusDays(68); break; default: - throw new IllegalArgumentException("Unknown christian holiday type " + ch.type()); + throw new IllegalArgumentException("Unknown christian holiday type " + christianHolidayConfiguration.type()); } - easterSunday = new MoveDateRelative(easterSunday).apply(ch); - return new CreateHoliday(easterSunday).apply(ch); + + return new MoveDateRelative(christianHoliday).apply(christianHolidayConfiguration) + .map(movedDate -> new CreateHoliday(christianHoliday, movedDate)) + .orElseGet(() -> new CreateHoliday(christianHoliday)) + .apply(christianHolidayConfiguration); + }) .collect(toList()); } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/DescribedDateHolder.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/DescribedDateHolder.java index 91d9ee1e7..8690625c8 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/DescribedDateHolder.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/DescribedDateHolder.java @@ -6,16 +6,26 @@ class DescribedDateHolder { - private final LocalDate date; + private final LocalDate actualDate; + private final LocalDate observedDate; private final Described described; - public DescribedDateHolder(final Described described, final LocalDate date) { - this.date = date; + DescribedDateHolder(final Described described, final LocalDate actualDate) { + this(described, actualDate, null); + } + + DescribedDateHolder(final Described described, final LocalDate actualDate, final LocalDate observedDate) { + this.actualDate = actualDate; + this.observedDate = observedDate; this.described = described; } - public LocalDate getDate() { - return date; + public LocalDate getActualDate() { + return actualDate; + } + + public LocalDate getObservedDate() { + return observedDate; } public Described getDescribed() { diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedParser.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedParser.java index 7f7dd6057..ccff5700c 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedParser.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedParser.java @@ -8,6 +8,7 @@ import de.focus_shift.jollyday.core.parser.predicates.ValidLimitation; import de.focus_shift.jollyday.core.spi.Holidays; +import java.time.LocalDate; import java.time.Year; import java.util.List; @@ -22,8 +23,12 @@ public class FixedParser implements HolidayParser { public List parse(final Year year, final Holidays holidays) { return holidays.fixed().stream() .filter(new ValidLimitation(year)) - .map(fixed -> new DescribedDateHolder(fixed, new MoveDateRelative(new FixedToLocalDate(year).apply(fixed)).apply(fixed))) - .map(describedDateHolder -> new CreateHoliday(describedDateHolder.getDate()).apply(describedDateHolder.getDescribed())) + .map(fixedConfiguration -> { + final LocalDate actualDate = new FixedToLocalDate(year).apply(fixedConfiguration); + final LocalDate observedDate = new MoveDateRelative(actualDate).apply(fixedConfiguration).orElse(null); + return new DescribedDateHolder(fixedConfiguration, actualDate, observedDate); + }) + .map(describedDateHolder -> new CreateHoliday(describedDateHolder.getActualDate(), describedDateHolder.getObservedDate()).apply(describedDateHolder.getDescribed())) .collect(toList()); } } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayBetweenFixedParser.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayBetweenFixedParser.java index a4c27590b..62f41a16c 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayBetweenFixedParser.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayBetweenFixedParser.java @@ -29,7 +29,7 @@ public List parse(final Year year, final Holidays holidays) { ).apply(fwm) ) ) - .map(holder -> new CreateHoliday(holder.getDate()).apply(holder.getDescribed())) + .map(holder -> new CreateHoliday(holder.getActualDate()).apply(holder.getDescribed())) .collect(toList()); } } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayInMonthParser.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayInMonthParser.java index dde60bd1f..6c779def1 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayInMonthParser.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayInMonthParser.java @@ -22,7 +22,7 @@ public List parse(final Year year, final Holidays holidays) { return holidays.fixedWeekdays().stream() .filter(new ValidLimitation(year)) .map(fwm -> new DescribedDateHolder(fwm, new FindWeekDayInMonth(year).apply(fwm))) - .map(holder -> new CreateHoliday(holder.getDate()).apply(holder.getDescribed())) + .map(holder -> new CreateHoliday(holder.getActualDate()).apply(holder.getDescribed())) .collect(toList()); } } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayRelativeToFixedParser.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayRelativeToFixedParser.java index d8900d211..8b2e5c78d 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayRelativeToFixedParser.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/FixedWeekdayRelativeToFixedParser.java @@ -28,7 +28,7 @@ public List parse(final Year year, final Holidays holidays) { new FindWeekDayRelativeToDate(new FixedToLocalDate(year).apply(weekdayRelativeToFixed.day())).apply(weekdayRelativeToFixed) ) ) - .map(holder -> new CreateHoliday(holder.getDate()).apply(holder.getDescribed())) + .map(holder -> new CreateHoliday(holder.getActualDate()).apply(holder.getDescribed())) .collect(toList()); } } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParser.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParser.java index ea0ce6e93..3d1c05f2c 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParser.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParser.java @@ -80,8 +80,8 @@ public List parse(final Year year, final Holidays holidays) { } return islamicHolidays - .map(date -> new MoveDateRelative(date).apply(islamicHoliday)) - .map(date -> new CreateHoliday(date).apply(islamicHoliday)); + .map(date -> new DescribedDateHolder(islamicHoliday, date, new MoveDateRelative(date).apply(islamicHoliday).orElse(null))) + .map(describedDateHolder -> new CreateHoliday(describedDateHolder.getActualDate(), describedDateHolder.getObservedDate()).apply(islamicHoliday)); }) .collect(toList()); diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/RelativeToEasterSundayParser.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/RelativeToEasterSundayParser.java index f8af31d2c..b597a3ace 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/RelativeToEasterSundayParser.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/parser/impl/RelativeToEasterSundayParser.java @@ -22,7 +22,7 @@ public List parse(final Year year, final Holidays holidays) { return holidays.relativeToEasterSunday().stream() .filter(new ValidLimitation(year)) .map(res -> new DescribedDateHolder(res, new CalculateEasterSunday(year).apply(res.chronology()).plus(res.days()))) - .map(holder -> new CreateHoliday(holder.getDate()).apply(holder.getDescribed())) + .map(holder -> new CreateHoliday(holder.getActualDate()).apply(holder.getDescribed())) .collect(toList()); } } diff --git a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/spi/Holidays.java b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/spi/Holidays.java index 594346b46..9a55f6d7c 100644 --- a/jollyday-core/src/main/java/de/focus_shift/jollyday/core/spi/Holidays.java +++ b/jollyday-core/src/main/java/de/focus_shift/jollyday/core/spi/Holidays.java @@ -11,7 +11,7 @@ public interface Holidays { /** * see {@link Fixed} * - * @return list of all fixed holidays + * @return list of all fixed holidays configurations */ List fixed(); diff --git a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/HolidayTest.java b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/HolidayTest.java index 69240005f..c494e8d31 100644 --- a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/HolidayTest.java +++ b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/HolidayTest.java @@ -51,12 +51,34 @@ void testHolidayDescription() { } @Test - void testHolidayEquals() { + void ensureToReturnObservedDateIfPresent() { + final LocalDate observedDate = LocalDate.of(2011, 2, 10); + final Holiday holiday = new Holiday(LocalDate.of(2011, 2, 2), observedDate, "CHRISTMAS", PUBLIC_HOLIDAY); + assertThat(holiday.getDate()).isEqualTo(observedDate); + } + + @Test + void ensureToReturnActualDateIfObservedDateIsNotPresent() { + final LocalDate date = LocalDate.of(2011, 2, 2); + final Holiday holiday = new Holiday(date, "CHRISTMAS", PUBLIC_HOLIDAY); + assertThat(holiday.getDate()).isEqualTo(date); + } + + @Test + void ensuresHolidayAreEqual() { final Holiday h1 = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", PUBLIC_HOLIDAY); assertThat(h1).isEqualTo(h1); final Holiday h2b = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", PUBLIC_HOLIDAY); assertThat(h1).isEqualTo(h2b); + } + + @Test + void ensuresHolidayAreNotEqual() { + final Holiday h1 = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", PUBLIC_HOLIDAY); + assertThat(h1) + .isNotEqualTo(null) + .isNotEqualTo(new Object()); final Holiday h2 = new Holiday(LocalDate.of(2011, 2, 1), "CHRISTMAS", PUBLIC_HOLIDAY); assertThat(h1).isNotEqualTo(h2); diff --git a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelativeTest.java b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelativeTest.java index ab3d23e4b..0a43691dc 100644 --- a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelativeTest.java +++ b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/functions/MoveDateRelativeTest.java @@ -6,6 +6,7 @@ import java.time.DayOfWeek; import java.time.LocalDate; import java.util.List; +import java.util.Optional; import static java.time.Month.FEBRUARY; import static java.time.Month.MARCH; @@ -18,8 +19,8 @@ void ensureToConvertMovableToNextLocalDate() { final Movable.MovingCondition movingCondition = new Movable.MovingCondition() { @Override - public DayOfWeek substitute() { - return DayOfWeek.WEDNESDAY; + public DayOfWeek weekday() { + return DayOfWeek.SUNDAY; } @Override @@ -28,18 +29,15 @@ public With with() { } @Override - public DayOfWeek weekday() { - return DayOfWeek.SUNDAY; + public DayOfWeek substitute() { + return DayOfWeek.WEDNESDAY; } }; final Movable movable = () -> List.of(movingCondition); - final LocalDate localDate = new MoveDateRelative(LocalDate.of(2024, 2, 28)).apply(movable); - assertThat(localDate) - .hasYear(2024) - .hasMonth(MARCH) - .hasDayOfMonth(3); + final Optional maybeMovedDate = new MoveDateRelative(LocalDate.of(2024, 2, 28)).apply(movable); + assertThat(maybeMovedDate).hasValue(LocalDate.of(2024, MARCH, 3)); } @Test @@ -64,15 +62,12 @@ public DayOfWeek weekday() { final Movable movable = () -> List.of(movingCondition); - final LocalDate localDate = new MoveDateRelative(LocalDate.of(2024, 2, 28)).apply(movable); - assertThat(localDate) - .hasYear(2024) - .hasMonth(FEBRUARY) - .hasDayOfMonth(25); + final Optional maybeMovedDate = new MoveDateRelative(LocalDate.of(2024, 2, 28)).apply(movable); + assertThat(maybeMovedDate).hasValue(LocalDate.of(2024, FEBRUARY, 25)); } @Test - void ensureToReturnProvidedLocalDateIfMovingConditionIsFalse() { + void ensureToReturnEmptyIfMovingConditionIsFalse() { final Movable.MovingCondition movingCondition = new Movable.MovingCondition() { @Override @@ -93,10 +88,7 @@ public DayOfWeek weekday() { final Movable movable = () -> List.of(movingCondition); - final LocalDate localDate = new MoveDateRelative(LocalDate.of(2024, 2, 28)).apply(movable); - assertThat(localDate) - .hasYear(2024) - .hasMonth(FEBRUARY) - .hasDayOfMonth(28); + final Optional maybeMovedDate = new MoveDateRelative(LocalDate.of(2024, 2, 28)).apply(movable); + assertThat(maybeMovedDate).isEmpty(); } } diff --git a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParserTest.java b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParserTest.java index 6508d6c57..fd359216c 100644 --- a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParserTest.java +++ b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/impl/IslamicHolidayParserTest.java @@ -10,6 +10,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.time.DayOfWeek; +import java.time.LocalDate; import java.time.Year; import java.util.List; @@ -54,5 +55,7 @@ public DayOfWeek weekday() { // ID_UL_ADHA_2 will be on a sunday in 2022 final List calculatedHoliday = sut.parse(Year.of(2022), holidays); assertThat(calculatedHoliday.get(0).getDate().getDayOfWeek()).isEqualTo(DayOfWeek.MONDAY); + assertThat(calculatedHoliday.get(0).getActualDate().getDayOfWeek()).isEqualTo(DayOfWeek.SUNDAY); + assertThat(calculatedHoliday.get(0).getObservedDate()).map(LocalDate::getDayOfWeek).hasValue(DayOfWeek.MONDAY); } }