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 0a43691dc..ced4e4f7a 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 @@ -5,12 +5,17 @@ import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.temporal.TemporalAdjusters; import java.util.List; import java.util.Optional; import static java.time.Month.FEBRUARY; import static java.time.Month.MARCH; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class MoveDateRelativeTest { @@ -91,4 +96,34 @@ public DayOfWeek weekday() { final Optional maybeMovedDate = new MoveDateRelative(LocalDate.of(2024, 2, 28)).apply(movable); assertThat(maybeMovedDate).isEmpty(); } + + @Test + void ensureOnInvalidConditionTheMappingWillNotBeApplied() { + + final Movable.MovingCondition movingCondition = new Movable.MovingCondition() { + @Override + public DayOfWeek weekday() { + return DayOfWeek.SUNDAY; + } + + @Override + public With with() { + return With.NEXT; + } + + @Override + public DayOfWeek substitute() { + return DayOfWeek.WEDNESDAY; + } + }; + + final Movable movable = () -> List.of(movingCondition); + + final LocalDate localDate = mock(LocalDate.class); + when(localDate.getDayOfWeek()).thenReturn(DayOfWeek.SATURDAY); + + new MoveDateRelative(localDate).apply(movable); + verify(localDate, never()).with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); + } } +