Skip to content

Commit 983a022

Browse files
committed
ProductTest is fully working
1 parent c00d71b commit 983a022

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

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

1212
protected Product(String name, BigDecimal price, BigDecimal tax) {
13-
this.name = name;
13+
if (name == null || name.equals("")) {
14+
throw new IllegalArgumentException(
15+
"You cannot create products with null or empty name."
16+
);
17+
}
18+
if (price == null || price.signum() == -1) {
19+
throw new IllegalArgumentException(
20+
"You cannot create products with null or negative price."
21+
);
22+
}
23+
this.name = name;
1424
this.price = price;
1525
this.taxPercent = tax;
1626
}
1727

1828
public String getName() {
19-
return null;
29+
return this.name;
2030
}
2131

2232
public BigDecimal getPrice() {
23-
return null;
24-
}
33+
return price;
34+
}
2535

26-
public BigDecimal getTaxPercent() {
27-
return null;
28-
}
36+
public BigDecimal getTaxPercent() {
37+
return taxPercent;
38+
}
2939

30-
public BigDecimal getPriceWithTax() {
31-
return null;
40+
public BigDecimal getPriceWithTax() {
41+
return this.price.multiply(this.taxPercent).add(this.price);
3242
}
3343
}

0 commit comments

Comments
 (0)