52 lines
2.1 KiB
Java
52 lines
2.1 KiB
Java
package oving5.ticket;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
import java.time.LocalDateTime;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class PeriodTicketTest {
|
|
|
|
@Test
|
|
@DisplayName("Check that the ticket is valid within the period")
|
|
public void testIsValidWhenWithinPeriod() {
|
|
LocalDateTime start = LocalDateTime.now().minusDays(1);
|
|
LocalDateTime end = LocalDateTime.now().plusDays(1);
|
|
PeriodTicket ticket = new PeriodTicket(start, end);
|
|
assertTrue(ticket.scan(), "The ticket should be valid within the period");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Check that the ticket is not valid before the period")
|
|
public void testIsNotValidWhenBeforePeriod() {
|
|
LocalDateTime start = LocalDateTime.now().plusDays(1);
|
|
LocalDateTime end = LocalDateTime.now().plusDays(2);
|
|
PeriodTicket ticket = new PeriodTicket(start, end);
|
|
assertFalse(ticket.scan(), "The ticket should not be valid before the period");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Check that the ticket is not valid after the period")
|
|
public void testIsNotValidWhenAfterPeriod() {
|
|
LocalDateTime start = LocalDateTime.now().minusDays(2);
|
|
LocalDateTime end = LocalDateTime.now().minusDays(1);
|
|
PeriodTicket ticket = new PeriodTicket(start, end);
|
|
assertFalse(ticket.scan(), "The ticket should not be valid after the period");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Check that the ticket throws IllegalArgumentException when the start date is "
|
|
+ "after the end date")
|
|
public void testThrowsExceptionWhenStartIsAfterEnd() {
|
|
LocalDateTime start = LocalDateTime.now().plusDays(1);
|
|
LocalDateTime end = LocalDateTime.now().minusDays(1);
|
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
new PeriodTicket(start, end);
|
|
}, "The ticket should throw IllegalArgumentException when the start date is after the "
|
|
+ "end date");
|
|
}
|
|
}
|