Skip to content

Commit bde3ae8

Browse files
committed
ProductTest is fully working
1 parent e84f183 commit bde3ae8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/pl/edu/agh/mwo/invoice/product/Product.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public abstract class Product {
1010
private final BigDecimal taxPercent;
1111

1212
protected Product(String name, BigDecimal price, BigDecimal tax) {
13+
if (name == null || name.isEmpty()) {
14+
throw new IllegalArgumentException("Product name cannot be null and cannot be empty");
15+
}
16+
if (price == null || price.signum() == -1) {
17+
throw new IllegalArgumentException("Price cannot be negative and null.");
18+
}
1319
this.name = name;
1420
this.price = price;
1521
this.taxPercent = tax;
@@ -20,14 +26,14 @@ public String getName() {
2026
}
2127

2228
public BigDecimal getPrice() {
23-
return null;
29+
return price;
2430
}
2531

2632
public BigDecimal getTaxPercent() {
27-
return null;
33+
return taxPercent;
2834
}
2935

3036
public BigDecimal getPriceWithTax() {
31-
return null;
37+
return this.price.multiply(this.taxPercent).add(this.price);
3238
}
3339
}

0 commit comments

Comments
 (0)