Skip to content

Commit

Permalink
Feat: Updated validation for share
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 25, 2026
1 parent 290fdab commit 706db1d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 706db1d

Please sign in to comment.