From 75d31f4604034642d599cb823a34fef0b4cf7475 Mon Sep 17 00:00:00 2001 From: maywald Date: Sun, 11 Jan 2026 13:24:14 +0100 Subject: [PATCH 1/4] First priductTest working --- src/main/java/pl/edu/agh/mwo/invoice/product/OtherProduct.java | 1 + src/main/java/pl/edu/agh/mwo/invoice/product/Product.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/pl/edu/agh/mwo/invoice/product/OtherProduct.java b/src/main/java/pl/edu/agh/mwo/invoice/product/OtherProduct.java index e324fe5a4..be62a994b 100644 --- a/src/main/java/pl/edu/agh/mwo/invoice/product/OtherProduct.java +++ b/src/main/java/pl/edu/agh/mwo/invoice/product/OtherProduct.java @@ -3,6 +3,7 @@ import java.math.BigDecimal; public class OtherProduct extends Product { + public OtherProduct(String name, BigDecimal price) { super(name, price, new BigDecimal("0.23")); } 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 b87e1e174b3bf407b91cc747385d3e655fc3d5c8 Mon Sep 17 00:00:00 2001 From: maywald Date: Sun, 11 Jan 2026 13:50:56 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Kolejen=20testy=20przesz=C5=82y!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/pl/edu/agh/mwo/invoice/product/Product.java | 8 +++++--- 1 file changed, 5 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..62f8d8f07 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,16 @@ public String getName() { } public BigDecimal getPrice() { - return null; + return this.price; } public BigDecimal getTaxPercent() { - return null; + return this.taxPercent; } public BigDecimal getPriceWithTax() { - return null; + BigDecimal result = this.price.multiply(this.taxPercent); + return (BigDecimal)price.add(result); + } } From 573b94a1202f7e7ca0c014fc47f8e802b5ade908 Mon Sep 17 00:00:00 2001 From: MajowyLas Date: Sun, 11 Jan 2026 14:02:08 +0100 Subject: [PATCH 3/4] IllegalArgumentException - handling --- .../pl/edu/agh/mwo/invoice/product/Product.java | 14 ++++++++++++++ 1 file changed, 14 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 62f8d8f07..d0c2f5850 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 @@ -9,12 +9,26 @@ public abstract class Product { private final BigDecimal taxPercent; + protected Product(String name, BigDecimal price, BigDecimal tax) { + + if(name == null) { + throw new IllegalArgumentException("name cannot be null"); + } this.name = name; + + if(price == null) { + throw new IllegalArgumentException("price cannot be null"); + } this.price = price; + + if(tax == null) { + throw new IllegalArgumentException("tax cannot be null"); + } this.taxPercent = tax; } + public String getName() { return this.name; } From 1fa3a1e3de92600c1d686ac3d4c7a4e6b9eb2706 Mon Sep 17 00:00:00 2001 From: MajowyLas Date: Sun, 11 Jan 2026 14:19:19 +0100 Subject: [PATCH 4/4] Rest of the tests --- .../java/pl/edu/agh/mwo/invoice/product/Product.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 d0c2f5850..dc09e2fb7 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 @@ -12,18 +12,18 @@ public abstract class Product { protected Product(String name, BigDecimal price, BigDecimal tax) { - if(name == null) { - throw new IllegalArgumentException("name cannot be null"); + if(name == null || name.isBlank()) { + throw new IllegalArgumentException("Product name cannot be null"); } this.name = name; if(price == null) { - throw new IllegalArgumentException("price cannot be null"); + throw new IllegalArgumentException("Price cannot be null"); } this.price = price; - if(tax == null) { - throw new IllegalArgumentException("tax cannot be null"); + if(tax == null|| price.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("Tax percent cannot be null"); } this.taxPercent = tax; }