utilisation d'une exception dédiée au lieu de IllegalArgument
This commit is contained in:
parent
f9518d068d
commit
fac36fb241
3 changed files with 11 additions and 4 deletions
|
|
@ -4,9 +4,9 @@ public class FeeCalculator {
|
||||||
|
|
||||||
public static double calculateFee(Visitor visitor, TicketType ticketType) {
|
public static double calculateFee(Visitor visitor, TicketType ticketType) {
|
||||||
if (TicketType.HALF_DAY != ticketType && TicketType.FULL_DAY != 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);
|
return visitor.calculateFee(ticketType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.example;
|
||||||
|
|
||||||
|
public class InvalidTicketTypeException extends IllegalArgumentException {
|
||||||
|
public InvalidTicketTypeException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ class FeeCalculatorTest {
|
||||||
|
|
||||||
//WHEN
|
//WHEN
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
InvalidTicketTypeException.class,
|
||||||
() -> FeeCalculator.calculateFee(child, TicketType.WEEK)
|
() -> FeeCalculator.calculateFee(child, TicketType.WEEK)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ class FeeCalculatorTest {
|
||||||
|
|
||||||
//WHEN
|
//WHEN
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
InvalidTicketTypeException.class,
|
||||||
() -> FeeCalculator.calculateFee(child, TicketType.WEEK)
|
() -> FeeCalculator.calculateFee(child, TicketType.WEEK)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue