diff --git a/src/main/java/Model/Stock.java b/src/main/java/Model/Stock.java index 6916dc3..52c1fd2 100644 --- a/src/main/java/Model/Stock.java +++ b/src/main/java/Model/Stock.java @@ -10,6 +10,19 @@ public class Stock { private final List prices; public Stock(String symbol, String company, BigDecimal salesPrice) { + if (symbol == null || symbol.isBlank()) { + throw new IllegalArgumentException("Symbol cannot be null or blank"); + } + if (company == null || company.isBlank()) { + throw new IllegalArgumentException("Company name cannot be null or blank"); + } + if (salesPrice == null) { + throw new IllegalArgumentException("Initial sales price cannot be null"); + } + if (salesPrice.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Initial sales price cannot be negative"); + } + this.symbol = symbol; this.company = company; this.prices = new ArrayList<>(); @@ -29,6 +42,12 @@ public BigDecimal getSalesPrice() { } public void addNewSalesPrice(BigDecimal price) { + if (price == null) { + throw new IllegalArgumentException("Price cannot be null"); + } + if (price.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Price cannot be negative"); + } prices.add(price); }