Skip to content

Commit

Permalink
Merge pull request #716 from focus-shift/fix-parser-filter
Browse files Browse the repository at this point in the history
Add test for invalid moving condition for MoveDateRelative
  • Loading branch information
derTobsch authored Jan 3, 2025
2 parents f4c52a3 + 150d590 commit 00427a2
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -91,4 +96,34 @@ public DayOfWeek weekday() {
final Optional<LocalDate> 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));
}
}

0 comments on commit 00427a2

Please sign in to comment.