diff --git a/src/main/java/Model/Share.java b/src/main/java/Model/Share.java index dee79dd..92d6101 100644 --- a/src/main/java/Model/Share.java +++ b/src/main/java/Model/Share.java @@ -8,6 +8,22 @@ public class Share { private final BigDecimal purchasePrice; public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) { + if (stock == null) { + throw new IllegalArgumentException("Stock cannot be null"); + } + if (quantity == null) { + throw new IllegalArgumentException("Quantity cannot be null"); + } + if (quantity.compareTo(BigDecimal.ZERO) <= 0) { + throw new IllegalArgumentException("Quantity must be greater than zero"); + } + if (purchasePrice == null) { + throw new IllegalArgumentException("Purchase price cannot be null"); + } + if (purchasePrice.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Purchase price cannot be negative"); + } + this.stock = stock; this.quantity = quantity; this.purchasePrice = purchasePrice;