Skip to content

Commit

Permalink
Merge pull request #688 from focus-shift/cleanups
Browse files Browse the repository at this point in the history
Cleanups
  • Loading branch information
derTobsch authored Dec 6, 2024
2 parents 8289743 + b6ad9d9 commit 7fc1d9f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public class FixedWeekdayRelativeToFixedParser implements HolidayParser {
public List<Holiday> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,185 +15,84 @@ 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();
}

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

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

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

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

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

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

@Property
void ensureIsNotValidAfterTheIntervalFromAndTo(@ForAll @YearRange(min = 2081, max = 2150) final Year year) {
final Limited limited = new Limited() {
final Limited limited = getLimited(Year.of(1900), 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
public YearCycle cycle() {
return YearCycle.EVERY_YEAR;
}
};

final boolean isValid = new ValidFromTo(year).test(limited);
assertThat(isValid).isFalse();
}
}

0 comments on commit 7fc1d9f

Please sign in to comment.