From a8dbdba9caafd75e626df3fe2f15d5a2d1417810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Wed, 8 Jan 2020 15:31:13 +0100 Subject: [PATCH 1/9] Specs! --- .../pl/edu/agh/mwo/invoice/InvoiceTest.java | 107 ++++++++++++++++++ .../agh/mwo/invoice/product/ProductTest.java | 57 ++++++++++ 2 files changed, 164 insertions(+) create mode 100644 src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java create mode 100644 src/test/java/pl/edu/agh/mwo/invoice/product/ProductTest.java diff --git a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java new file mode 100644 index 000000000..8dce08e28 --- /dev/null +++ b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java @@ -0,0 +1,107 @@ +package pl.edu.agh.mwo.invoice; + +import java.math.BigDecimal; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import pl.edu.agh.mwo.invoice.Invoice; +import pl.edu.agh.mwo.invoice.product.DairyProduct; +import pl.edu.agh.mwo.invoice.product.OtherProduct; +import pl.edu.agh.mwo.invoice.product.Product; +import pl.edu.agh.mwo.invoice.product.TaxFreeProduct; + +public class InvoiceTest { + private Invoice invoice; + + @Before + public void createEmptyInvoiceForTheTest() { + invoice = new Invoice(); + } + + @Test + public void testEmptyInvoiceHasEmptySubtotal() { + Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getSubtotal())); + } + + @Test + public void testEmptyInvoiceHasEmptyTaxAmount() { + Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getTax())); + } + + @Test + public void testEmptyInvoiceHasEmptyTotal() { + Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getTotal())); + } + + @Test + public void testInvoiceHasTheSameSubtotalAndTotalIfTaxIsZero() { + Product taxFreeProduct = new TaxFreeProduct("Warzywa", new BigDecimal("199.99")); + invoice.addProduct(taxFreeProduct); + Assert.assertThat(invoice.getTotal(), Matchers.comparesEqualTo(invoice.getSubtotal())); + } + + @Test + public void testInvoiceHasProperSubtotalForManyProducts() { + invoice.addProduct(new TaxFreeProduct("Owoce", new BigDecimal("200"))); + invoice.addProduct(new DairyProduct("Maslanka", new BigDecimal("100"))); + invoice.addProduct(new OtherProduct("Wino", new BigDecimal("10"))); + Assert.assertThat(new BigDecimal("310"), Matchers.comparesEqualTo(invoice.getSubtotal())); + } + + @Test + public void testInvoiceHasProperTaxValueForManyProduct() { + // tax: 0 + invoice.addProduct(new TaxFreeProduct("Pampersy", new BigDecimal("200"))); + // tax: 8 + invoice.addProduct(new DairyProduct("Kefir", new BigDecimal("100"))); + // tax: 2.30 + invoice.addProduct(new OtherProduct("Piwko", new BigDecimal("10"))); + Assert.assertThat(new BigDecimal("10.30"), Matchers.comparesEqualTo(invoice.getTax())); + } + + @Test + public void testInvoiceHasProperTotalValueForManyProduct() { + // price with tax: 200 + invoice.addProduct(new TaxFreeProduct("Maskotki", new BigDecimal("200"))); + // price with tax: 108 + invoice.addProduct(new DairyProduct("Maslo", new BigDecimal("100"))); + // price with tax: 12.30 + invoice.addProduct(new OtherProduct("Chipsy", new BigDecimal("10"))); + Assert.assertThat(new BigDecimal("320.30"), Matchers.comparesEqualTo(invoice.getTotal())); + } + + @Test + public void testInvoiceHasPropoerSubtotalWithQuantityMoreThanOne() { + // 2x kubek - price: 10 + invoice.addProduct(new TaxFreeProduct("Kubek", new BigDecimal("5")), 2); + // 3x kozi serek - price: 30 + invoice.addProduct(new DairyProduct("Kozi Serek", new BigDecimal("10")), 3); + // 1000x pinezka - price: 10 + invoice.addProduct(new OtherProduct("Pinezka", new BigDecimal("0.01")), 1000); + Assert.assertThat(new BigDecimal("50"), Matchers.comparesEqualTo(invoice.getSubtotal())); + } + + @Test + public void testInvoiceHasPropoerTotalWithQuantityMoreThanOne() { + // 2x chleb - price with tax: 10 + invoice.addProduct(new TaxFreeProduct("Chleb", new BigDecimal("5")), 2); + // 3x chedar - price with tax: 32.40 + invoice.addProduct(new DairyProduct("Chedar", new BigDecimal("10")), 3); + // 1000x pinezka - price with tax: 12.30 + invoice.addProduct(new OtherProduct("Pinezka", new BigDecimal("0.01")), 1000); + Assert.assertThat(new BigDecimal("54.70"), Matchers.comparesEqualTo(invoice.getTotal())); + } + + @Test(expected = IllegalArgumentException.class) + public void testInvoiceWithZeroQuantity() { + invoice.addProduct(new TaxFreeProduct("Tablet", new BigDecimal("1678")), 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testInvoiceWithNegativeQuantity() { + invoice.addProduct(new DairyProduct("Zsiadle mleko", new BigDecimal("5.55")), -1); + } +} diff --git a/src/test/java/pl/edu/agh/mwo/invoice/product/ProductTest.java b/src/test/java/pl/edu/agh/mwo/invoice/product/ProductTest.java new file mode 100644 index 000000000..9b3c5bd6e --- /dev/null +++ b/src/test/java/pl/edu/agh/mwo/invoice/product/ProductTest.java @@ -0,0 +1,57 @@ +package pl.edu.agh.mwo.invoice.product; + +import java.math.BigDecimal; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Test; + +import pl.edu.agh.mwo.invoice.product.Product; + +public class ProductTest { + @Test + public void testProductNameIsCorrect() { + Product product = new OtherProduct("buty", new BigDecimal("100.0")); + Assert.assertEquals("buty", product.getName()); + } + + @Test + public void testProductPriceAndTaxWithDefaultTax() { + Product product = new OtherProduct("Ogorki", new BigDecimal("100.0")); + Assert.assertThat(new BigDecimal("100"), Matchers.comparesEqualTo(product.getPrice())); + Assert.assertThat(new BigDecimal("0.23"), Matchers.comparesEqualTo(product.getTaxPercent())); + } + + @Test + public void testProductPriceAndTaxWithDairyProduct() { + Product product = new DairyProduct("Szarlotka", new BigDecimal("100.0")); + Assert.assertThat(new BigDecimal("100"), Matchers.comparesEqualTo(product.getPrice())); + Assert.assertThat(new BigDecimal("0.08"), Matchers.comparesEqualTo(product.getTaxPercent())); + } + + @Test + public void testPriceWithTax() { + Product product = new DairyProduct("Oscypek", new BigDecimal("100.0")); + Assert.assertThat(new BigDecimal("108"), Matchers.comparesEqualTo(product.getPriceWithTax())); + } + + @Test(expected = IllegalArgumentException.class) + public void testProductWithNullName() { + new OtherProduct(null, new BigDecimal("100.0")); + } + + @Test(expected = IllegalArgumentException.class) + public void testProductWithEmptyName() { + new TaxFreeProduct("", new BigDecimal("100.0")); + } + + @Test(expected = IllegalArgumentException.class) + public void testProductWithNullPrice() { + new DairyProduct("Banany", null); + } + + @Test(expected = IllegalArgumentException.class) + public void testProductWithNegativePrice() { + new TaxFreeProduct("Mandarynki", new BigDecimal("-1.00")); + } +} From 005f93bf3c60f18d725e58063bea02709c4a6b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sat, 5 Feb 2022 12:23:34 +0100 Subject: [PATCH 2/9] New invoice tests --- .../java/pl/edu/agh/mwo/invoice/InvoiceTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java index 8dce08e28..93666ea8c 100644 --- a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java +++ b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java @@ -36,6 +36,22 @@ public void testEmptyInvoiceHasEmptyTotal() { Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getTotal())); } + @Test + public void testInvoiceSubtotalWithTwoDifferentProducts() { + Product onions = new TaxFreeProduct("Warzywa", new BigDecimal("10")); + Product apples = new TaxFreeProduct("Owoce", new BigDecimal("10")); + invoice.addProduct(onions); + invoice.addProduct(apples); + Assert.assertThat(new BigDecimal("20"), Matchers.comparesEqualTo(invoice.getSubtotal())); + } + + @Test + public void testInvoiceSubtotalWithManySameProducts() { + Product onions = new TaxFreeProduct("Warzywa", new BigDecimal("10")); + invoice.addProduct(onions, 100); + Assert.assertThat(new BigDecimal("1000"), Matchers.comparesEqualTo(invoice.getSubtotal())); + } + @Test public void testInvoiceHasTheSameSubtotalAndTotalIfTaxIsZero() { Product taxFreeProduct = new TaxFreeProduct("Warzywa", new BigDecimal("199.99")); From d0b574259095f3391a1875e5a8e6414cfe4d0a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sat, 26 Feb 2022 16:22:29 +0100 Subject: [PATCH 3/9] Add test for null product check --- src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java index 93666ea8c..7f4b6f795 100644 --- a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java +++ b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java @@ -47,7 +47,7 @@ public void testInvoiceSubtotalWithTwoDifferentProducts() { @Test public void testInvoiceSubtotalWithManySameProducts() { - Product onions = new TaxFreeProduct("Warzywa", new BigDecimal("10")); + Product onions = new TaxFreeProduct("Warzywa", BigDecimal.valueOf(10)); invoice.addProduct(onions, 100); Assert.assertThat(new BigDecimal("1000"), Matchers.comparesEqualTo(invoice.getSubtotal())); } @@ -120,4 +120,9 @@ public void testInvoiceWithZeroQuantity() { public void testInvoiceWithNegativeQuantity() { invoice.addProduct(new DairyProduct("Zsiadle mleko", new BigDecimal("5.55")), -1); } + + @Test(expected = IllegalArgumentException.class) + public void testAddingNullProduct() { + invoice.addProduct(null); + } } From 6a09e8d2d6acf6bf9603c54a9feae8041b58a607 Mon Sep 17 00:00:00 2001 From: huzior Date: Sun, 11 Jan 2026 13:25:15 +0100 Subject: [PATCH 4/9] first test pass --- src/main/java/pl/edu/agh/mwo/invoice/product/Product.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java b/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java index 318de9ac9..d2edc9974 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java @@ -16,7 +16,7 @@ protected Product(String name, BigDecimal price, BigDecimal tax) { } public String getName() { - return null; + return this.name; } public BigDecimal getPrice() { From cd76d4fc4b94ec9cf14dabca5fe8071bf947f650 Mon Sep 17 00:00:00 2001 From: huzior Date: Sun, 11 Jan 2026 13:51:18 +0100 Subject: [PATCH 5/9] fix product class --- src/main/java/pl/edu/agh/mwo/invoice/product/Product.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java b/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java index d2edc9974..735e814df 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java @@ -20,14 +20,14 @@ public String getName() { } public BigDecimal getPrice() { - return null; + return this.price; } public BigDecimal getTaxPercent() { - return null; + return this.taxPercent; } public BigDecimal getPriceWithTax() { - return null; + return this.price.multiply(this.taxPercent).add(this.price); } } From 198e8680c124995a800cda43e5901b7032a40955 Mon Sep 17 00:00:00 2001 From: huzior Date: Sun, 11 Jan 2026 14:19:09 +0100 Subject: [PATCH 6/9] all tests of products pass --- src/main/java/pl/edu/agh/mwo/invoice/product/Product.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java b/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java index 735e814df..3f0ff9f82 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/product/Product.java @@ -10,6 +10,11 @@ public abstract class Product { private final BigDecimal taxPercent; protected Product(String name, BigDecimal price, BigDecimal tax) { + if (name==null || name.isEmpty()) { + throw new IllegalArgumentException("Product name cannot be null"); + } else if (price==null || price.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Product price cannot be null"); + } this.name = name; this.price = price; this.taxPercent = tax; From dc318101d32b14d40355d26b6132b6d97d54113d Mon Sep 17 00:00:00 2001 From: huzior Date: Sun, 11 Jan 2026 15:38:00 +0100 Subject: [PATCH 7/9] New pass tests --- .../java/pl/edu/agh/mwo/invoice/Invoice.java | 36 ++++++++++++++----- .../pl/edu/agh/mwo/invoice/InvoiceTest.java | 19 +++++----- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java index 56fe02359..929a96ae5 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java @@ -1,30 +1,50 @@ package pl.edu.agh.mwo.invoice; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import pl.edu.agh.mwo.invoice.product.Product; public class Invoice { - private Collection products; +// private Collection products +// = new ArrayList(); + + private Map products = new HashMap(); + public void addProduct(Product product) { - // TODO: implement + this.addProduct(product, 1); } public void addProduct(Product product, Integer quantity) { - // TODO: implement + this.products.put(product, quantity); } - public BigDecimal getSubtotal() { - return null; + public BigDecimal getNetValue() { + BigDecimal value = BigDecimal.ZERO; + // dla kardego produktu po mapie + //dodaj cene do value + + for (Product product : this.products.keySet()) { + Integer quantity = this.products.get(product); + BigDecimal price = product.getPrice(); + price = price.multiply(BigDecimal.valueOf(quantity)); + value = value.add(price); + } + + return value; } public BigDecimal getTax() { - return null; + + return BigDecimal.ZERO; } - public BigDecimal getTotal() { - return null; + public BigDecimal getGrossValue() { + + return BigDecimal.ZERO; } } diff --git a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java index 7f4b6f795..d85ac33d5 100644 --- a/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java +++ b/src/test/java/pl/edu/agh/mwo/invoice/InvoiceTest.java @@ -7,7 +7,6 @@ import org.junit.Before; import org.junit.Test; -import pl.edu.agh.mwo.invoice.Invoice; import pl.edu.agh.mwo.invoice.product.DairyProduct; import pl.edu.agh.mwo.invoice.product.OtherProduct; import pl.edu.agh.mwo.invoice.product.Product; @@ -23,7 +22,7 @@ public void createEmptyInvoiceForTheTest() { @Test public void testEmptyInvoiceHasEmptySubtotal() { - Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getSubtotal())); + Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getNetValue())); } @Test @@ -33,7 +32,7 @@ public void testEmptyInvoiceHasEmptyTaxAmount() { @Test public void testEmptyInvoiceHasEmptyTotal() { - Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getTotal())); + Assert.assertThat(BigDecimal.ZERO, Matchers.comparesEqualTo(invoice.getGrossValue())); } @Test @@ -42,21 +41,21 @@ public void testInvoiceSubtotalWithTwoDifferentProducts() { Product apples = new TaxFreeProduct("Owoce", new BigDecimal("10")); invoice.addProduct(onions); invoice.addProduct(apples); - Assert.assertThat(new BigDecimal("20"), Matchers.comparesEqualTo(invoice.getSubtotal())); + Assert.assertThat(new BigDecimal("20"), Matchers.comparesEqualTo(invoice.getNetValue())); } @Test public void testInvoiceSubtotalWithManySameProducts() { Product onions = new TaxFreeProduct("Warzywa", BigDecimal.valueOf(10)); invoice.addProduct(onions, 100); - Assert.assertThat(new BigDecimal("1000"), Matchers.comparesEqualTo(invoice.getSubtotal())); + Assert.assertThat(new BigDecimal("1000"), Matchers.comparesEqualTo(invoice.getNetValue())); } @Test public void testInvoiceHasTheSameSubtotalAndTotalIfTaxIsZero() { Product taxFreeProduct = new TaxFreeProduct("Warzywa", new BigDecimal("199.99")); invoice.addProduct(taxFreeProduct); - Assert.assertThat(invoice.getTotal(), Matchers.comparesEqualTo(invoice.getSubtotal())); + Assert.assertThat(invoice.getGrossValue(), Matchers.comparesEqualTo(invoice.getNetValue())); } @Test @@ -64,7 +63,7 @@ public void testInvoiceHasProperSubtotalForManyProducts() { invoice.addProduct(new TaxFreeProduct("Owoce", new BigDecimal("200"))); invoice.addProduct(new DairyProduct("Maslanka", new BigDecimal("100"))); invoice.addProduct(new OtherProduct("Wino", new BigDecimal("10"))); - Assert.assertThat(new BigDecimal("310"), Matchers.comparesEqualTo(invoice.getSubtotal())); + Assert.assertThat(new BigDecimal("310"), Matchers.comparesEqualTo(invoice.getNetValue())); } @Test @@ -86,7 +85,7 @@ public void testInvoiceHasProperTotalValueForManyProduct() { invoice.addProduct(new DairyProduct("Maslo", new BigDecimal("100"))); // price with tax: 12.30 invoice.addProduct(new OtherProduct("Chipsy", new BigDecimal("10"))); - Assert.assertThat(new BigDecimal("320.30"), Matchers.comparesEqualTo(invoice.getTotal())); + Assert.assertThat(new BigDecimal("320.30"), Matchers.comparesEqualTo(invoice.getGrossValue())); } @Test @@ -97,7 +96,7 @@ public void testInvoiceHasPropoerSubtotalWithQuantityMoreThanOne() { invoice.addProduct(new DairyProduct("Kozi Serek", new BigDecimal("10")), 3); // 1000x pinezka - price: 10 invoice.addProduct(new OtherProduct("Pinezka", new BigDecimal("0.01")), 1000); - Assert.assertThat(new BigDecimal("50"), Matchers.comparesEqualTo(invoice.getSubtotal())); + Assert.assertThat(new BigDecimal("50"), Matchers.comparesEqualTo(invoice.getNetValue())); } @Test @@ -108,7 +107,7 @@ public void testInvoiceHasPropoerTotalWithQuantityMoreThanOne() { invoice.addProduct(new DairyProduct("Chedar", new BigDecimal("10")), 3); // 1000x pinezka - price with tax: 12.30 invoice.addProduct(new OtherProduct("Pinezka", new BigDecimal("0.01")), 1000); - Assert.assertThat(new BigDecimal("54.70"), Matchers.comparesEqualTo(invoice.getTotal())); + Assert.assertThat(new BigDecimal("54.70"), Matchers.comparesEqualTo(invoice.getGrossValue())); } @Test(expected = IllegalArgumentException.class) From 8981af5b15ad66d6a3c183d0db4807497496d702 Mon Sep 17 00:00:00 2001 From: huzior Date: Sun, 11 Jan 2026 15:52:30 +0100 Subject: [PATCH 8/9] only 3 tests left to pass --- .../java/pl/edu/agh/mwo/invoice/Invoice.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java index 929a96ae5..7f1bc991c 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java @@ -39,12 +39,22 @@ public BigDecimal getNetValue() { } public BigDecimal getTax() { - - return BigDecimal.ZERO; + return getGrossValue().subtract(getNetValue()); } public BigDecimal getGrossValue() { + BigDecimal value = BigDecimal.ZERO; + // dla kardego produktu po mapie + //dodaj cene do value + + for (Product product : this.products.keySet()) { + Integer quantity = this.products.get(product); + BigDecimal price = product.getPriceWithTax(); + price = price.multiply(BigDecimal.valueOf(quantity)); + value = value.add(price); + } + + return value; - return BigDecimal.ZERO; } } From 52e13f29f52b1bba29781626de976a9166691609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Huzior?= Date: Thu, 12 Feb 2026 20:53:56 +0100 Subject: [PATCH 9/9] All test pass --- src/main/java/pl/edu/agh/mwo/invoice/Invoice.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java index 7f1bc991c..97002b930 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/Invoice.java @@ -16,11 +16,19 @@ public class Invoice { public void addProduct(Product product) { + if(product == null){ + throw new IllegalArgumentException ("Product cant be null"); + } this.addProduct(product, 1); } - public void addProduct(Product product, Integer quantity) { + public void addProduct(Product product, Integer quantity){ + if (quantity == null || quantity <= 0) { + throw new IllegalArgumentException("Quantity must be greater than 0"); + } + this.products.put(product, quantity); + } public BigDecimal getNetValue() {