utilisation d'une exception dédiée au lieu de IllegalArgument

This commit is contained in:
Feror 2025-01-23 12:29:31 +01:00
parent f9518d068d
commit fac36fb241
3 changed files with 11 additions and 4 deletions

View file

@ -4,7 +4,7 @@ public class FeeCalculator {
public static double calculateFee(Visitor visitor, TicketType ticketType) {
if (TicketType.HALF_DAY != ticketType && TicketType.FULL_DAY != ticketType) {
throw new IllegalArgumentException("Invalid ticket type");
throw new InvalidTicketTypeException("Invalid ticket type");
}
return visitor.calculateFee(ticketType);

View file

@ -0,0 +1,7 @@
package org.example;
public class InvalidTicketTypeException extends IllegalArgumentException {
public InvalidTicketTypeException(String message) {
super(message);
}
}

View file

@ -73,7 +73,7 @@ class FeeCalculatorTest {
//WHEN
assertThrows(
IllegalArgumentException.class,
InvalidTicketTypeException.class,
() -> FeeCalculator.calculateFee(child, TicketType.WEEK)
);
}
@ -85,7 +85,7 @@ class FeeCalculatorTest {
//WHEN
assertThrows(
IllegalArgumentException.class,
InvalidTicketTypeException.class,
() -> FeeCalculator.calculateFee(child, TicketType.WEEK)
);
}