From 706db1dc9f90b95ec00079f2847bfbb8b6e42667 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 25 May 2026 19:48:50 +0200 Subject: [PATCH] Feat: Updated validation for share --- .../idi/idatt2003/g40/mappe/model/Share.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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;