-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #717 from focus-shift/find-weekday-between-improve…
…ments Replace interator with Stream interation over localdates
- Loading branch information
Showing
2 changed files
with
90 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...e/src/test/java/de/focus_shift/jollyday/core/parser/functions/FindWeekDayBetweenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package de.focus_shift.jollyday.core.parser.functions; | ||
|
||
|
||
import de.focus_shift.jollyday.core.HolidayType; | ||
import de.focus_shift.jollyday.core.spi.Fixed; | ||
import de.focus_shift.jollyday.core.spi.FixedWeekdayBetweenFixed; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.time.Year; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class FindWeekDayBetweenTest { | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"MONDAY,2025-01-06", | ||
"WEDNESDAY,2025-01-08", | ||
"FRIDAY,2025-01-10", | ||
}) | ||
void ensureToFindFirstWeekdayBetweenTwoFixedDates(final DayOfWeek dayOfWeek, final LocalDate expectedDate) { | ||
final LocalDate firstMonday = LocalDate.of(2025, 1, 6); | ||
final LocalDate secondFriday = LocalDate.of(2025, 1, 17); | ||
final LocalDate actualDate = new FindWeekDayBetween(firstMonday, secondFriday).apply(getFixedWeekdayBetweenFixed(dayOfWeek)); | ||
assertThat(actualDate).isEqualTo(expectedDate); | ||
} | ||
|
||
@Test | ||
void ensureToReturnNullIfNoWeekdayWasFound() { | ||
final LocalDate monday = LocalDate.of(2025, 1, 6); | ||
final LocalDate tuesday = LocalDate.of(2025, 1, 7); | ||
final LocalDate actualDate = new FindWeekDayBetween(monday, tuesday).apply(getFixedWeekdayBetweenFixed(DayOfWeek.WEDNESDAY)); | ||
assertThat(actualDate).isNull(); | ||
} | ||
|
||
private static FixedWeekdayBetweenFixed getFixedWeekdayBetweenFixed(final DayOfWeek dayOfWeek) { | ||
|
||
return new FixedWeekdayBetweenFixed() { | ||
|
||
@Override | ||
public Fixed from() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Fixed to() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public DayOfWeek weekday() { | ||
return dayOfWeek; | ||
} | ||
|
||
@Override | ||
public String descriptionPropertiesKey() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public HolidayType holidayType() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Year validFrom() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Year validTo() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public YearCycle cycle() { | ||
return null; | ||
} | ||
}; | ||
} | ||
} |