Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for invalid moving condition for MoveDateRelative #716

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}

Loading