From 983a022860887d78485ab725d8462aa41cc149f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sun, 17 Jan 2021 14:42:56 +0100 Subject: [PATCH] ProductTest is fully working --- .../edu/agh/mwo/invoice/product/Product.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 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 318de9ac9..b122937ab 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,24 +10,34 @@ public abstract class Product { private final BigDecimal taxPercent; protected Product(String name, BigDecimal price, BigDecimal tax) { - this.name = name; + if (name == null || name.equals("")) { + throw new IllegalArgumentException( + "You cannot create products with null or empty name." + ); + } + if (price == null || price.signum() == -1) { + throw new IllegalArgumentException( + "You cannot create products with null or negative price." + ); + } + this.name = name; this.price = price; this.taxPercent = tax; } public String getName() { - return null; + return this.name; } public BigDecimal getPrice() { - return null; - } + return price; + } - public BigDecimal getTaxPercent() { - return null; - } + public BigDecimal getTaxPercent() { + return taxPercent; + } - public BigDecimal getPriceWithTax() { - return null; + public BigDecimal getPriceWithTax() { + return this.price.multiply(this.taxPercent).add(this.price); } }