diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Share.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Share.java index 3328a74..30aba43 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Share.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Share.java @@ -32,13 +32,25 @@ public final class Share { * @param quantity the quantity purchased * @param purchasePrice the price per unit at purchase time * - * @throws IllegalArgumentException if stock is null. + * @throws IllegalArgumentException if parameters are null or invalid. */ public Share(final Stock stock, final BigDecimal quantity, final BigDecimal purchasePrice) throws IllegalArgumentException { - if (stock == null) { - throw new IllegalArgumentException("Invalid stock!"); + if (stock == null + || quantity == null + || purchasePrice == null) { + throw new IllegalArgumentException("Invalid share configuration!"); + } + if (quantity.compareTo(BigDecimal.ZERO) <= 0) { + throw new IllegalArgumentException( + "Quantity cannot be negative or zero!" + ); + } + if (purchasePrice.compareTo(BigDecimal.ZERO) <= 0) { + throw new IllegalArgumentException( + "Purchase price cannot be negative or zero!" + ); } this.stock = stock; this.quantity = quantity;