From 39f3860bd26ff14326ebd3b2b34e4fc276f08748 Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Fri, 6 Dec 2024 09:27:59 +0100 Subject: [PATCH 1/3] tests: improve testing stucture of validFromTo --- .../parser/predicates/ValidFromToTest.java | 135 +++--------------- 1 file changed, 17 insertions(+), 118 deletions(-) diff --git a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java index 5e563b7b3..8dd2c4e4b 100644 --- a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java +++ b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java @@ -15,22 +15,7 @@ class ValidFromToTest { @Test void ensureFromAndToCanBothBeNullAndWillBeValidForever() { - final Limited limited = new Limited() { - @Override - public Year validFrom() { - return null; - } - - @Override - public Year validTo() { - return null; - } - - @Override - public YearCycle cycle() { - return YearCycle.EVERY_YEAR; - } - }; + final Limited limited = getLimited(null, null); final boolean isValid = new ValidFromTo(Year.of(2020)).test(limited); assertThat(isValid).isTrue(); @@ -38,22 +23,7 @@ public YearCycle cycle() { @Property void ensureFromCanBeNullAndToIsAYearAndWillBeValidUntilTo(@ForAll @YearRange(max = 2020) final Year year) { - final Limited limited = new Limited() { - @Override - public Year validFrom() { - return null; - } - - @Override - public Year validTo() { - return Year.of(2020); - } - - @Override - public YearCycle cycle() { - return YearCycle.EVERY_YEAR; - } - }; + final Limited limited = getLimited(null, Year.of(2020)); final boolean isValid = new ValidFromTo(year).test(limited); assertThat(isValid).isTrue(); @@ -61,22 +31,7 @@ public YearCycle cycle() { @Property void ensureFromBothBeNullAndToIsAYearAfter2020AndWillNotBeValid(@ForAll @YearRange(min = 2021) final Year year) { - final Limited limited = new Limited() { - @Override - public Year validFrom() { - return null; - } - - @Override - public Year validTo() { - return Year.of(2020); - } - - @Override - public YearCycle cycle() { - return YearCycle.EVERY_YEAR; - } - }; + final Limited limited = getLimited(null, Year.of(2020)); final boolean isValid = new ValidFromTo(year).test(limited); assertThat(isValid).isFalse(); @@ -84,22 +39,7 @@ public YearCycle cycle() { @Property void ensureToCanBeNullAndFromIsSetAndLimitedWillBeValidUntilThisYear(@ForAll @YearRange(min = 1900) final Year year) { - final Limited limited = new Limited() { - @Override - public Year validFrom() { - return Year.of(1900); - } - - @Override - public Year validTo() { - return null; - } - - @Override - public YearCycle cycle() { - return YearCycle.EVERY_YEAR; - } - }; + final Limited limited = getLimited(Year.of(1900), null); final boolean isValid = new ValidFromTo(year).test(limited); assertThat(isValid).isTrue(); @@ -107,22 +47,7 @@ public YearCycle cycle() { @Property void ensureToCanBeNullAndFromIsSetAndLimitedWillBeNotValidAfterThisYear(@ForAll @YearRange(min = 1800, max = 1899) final Year year) { - final Limited limited = new Limited() { - @Override - public Year validFrom() { - return Year.of(1900); - } - - @Override - public Year validTo() { - return null; - } - - @Override - public YearCycle cycle() { - return YearCycle.EVERY_YEAR; - } - }; + final Limited limited = getLimited(Year.of(1900), null); final boolean isValid = new ValidFromTo(year).test(limited); assertThat(isValid).isFalse(); @@ -130,22 +55,7 @@ public YearCycle cycle() { @Property void ensureIsOnlyValidInTheIntervalFromAndTo(@ForAll @YearRange(min = 1920, max = 2080) final Year year) { - final Limited limited = new Limited() { - @Override - public Year validFrom() { - return Year.of(1920); - } - - @Override - public Year validTo() { - return Year.of(2080); - } - - @Override - public YearCycle cycle() { - return YearCycle.EVERY_YEAR; - } - }; + final Limited limited = getLimited(Year.of(1920), Year.of(2080)); final boolean isValid = new ValidFromTo(year).test(limited); assertThat(isValid).isTrue(); @@ -153,22 +63,7 @@ public YearCycle cycle() { @Property void ensureIsNotValidBeforeTheIntervalFromAndTo(@ForAll @YearRange(min = 1700, max = 1919) final Year year) { - final Limited limited = new Limited() { - @Override - public Year validFrom() { - return Year.of(1920); - } - - @Override - public Year validTo() { - return Year.of(2080); - } - - @Override - public YearCycle cycle() { - return YearCycle.EVERY_YEAR; - } - }; + final Limited limited = getLimited(Year.of(1920), Year.of(2080)); final boolean isValid = new ValidFromTo(year).test(limited); assertThat(isValid).isFalse(); @@ -176,15 +71,22 @@ public YearCycle cycle() { @Property void ensureIsNotValidAfterTheIntervalFromAndTo(@ForAll @YearRange(min = 2081, max = 2150) final Year year) { - final Limited limited = new Limited() { + final Limited limited = getLimited(Year.of(1920), Year.of(2080)); + + final boolean isValid = new ValidFromTo(year).test(limited); + assertThat(isValid).isFalse(); + } + + private static Limited getLimited(Year fromYear, Year toYear) { + return new Limited() { @Override public Year validFrom() { - return Year.of(1920); + return fromYear; } @Override public Year validTo() { - return Year.of(2080); + return toYear; } @Override @@ -192,8 +94,5 @@ public YearCycle cycle() { return YearCycle.EVERY_YEAR; } }; - - final boolean isValid = new ValidFromTo(year).test(limited); - assertThat(isValid).isFalse(); } } From c5600da21fbb1bfb43bc082e55d1f537e3789bf7 Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Fri, 6 Dec 2024 09:28:41 +0100 Subject: [PATCH 2/3] tests: unify test range --- .../jollyday/core/parser/predicates/ValidFromToTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java index 8dd2c4e4b..eaf925905 100644 --- a/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java +++ b/jollyday-core/src/test/java/de/focus_shift/jollyday/core/parser/predicates/ValidFromToTest.java @@ -71,7 +71,7 @@ void ensureIsNotValidBeforeTheIntervalFromAndTo(@ForAll @YearRange(min = 1700, m @Property void ensureIsNotValidAfterTheIntervalFromAndTo(@ForAll @YearRange(min = 2081, max = 2150) final Year year) { - final Limited limited = getLimited(Year.of(1920), Year.of(2080)); + final Limited limited = getLimited(Year.of(1900), Year.of(2080)); final boolean isValid = new ValidFromTo(year).test(limited); assertThat(isValid).isFalse(); From b6ad9d95094a3ebd3ce75190cb1d39626d0fbc6c Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Fri, 6 Dec 2024 09:34:19 +0100 Subject: [PATCH 3/3] improve readability --- .../parser/impl/FixedWeekdayRelativeToFixedParser.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 1a8105aa3..d8900d211 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 @@ -22,7 +22,12 @@ public class FixedWeekdayRelativeToFixedParser implements HolidayParser { public List parse(final Year year, final Holidays holidays) { return holidays.fixedWeekdayRelativeToFixed().stream() .filter(new ValidLimitation(year)) - .map(fwrf -> new DescribedDateHolder(fwrf, new FindWeekDayRelativeToDate(new FixedToLocalDate(year).apply(fwrf.day())).apply(fwrf))) + .map(weekdayRelativeToFixed -> + new DescribedDateHolder( + weekdayRelativeToFixed, + new FindWeekDayRelativeToDate(new FixedToLocalDate(year).apply(weekdayRelativeToFixed.day())).apply(weekdayRelativeToFixed) + ) + ) .map(holder -> new CreateHoliday(holder.getDate()).apply(holder.getDescribed())) .collect(toList()); }