refactoring : comments - introduce assertion
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.example.refactoring._24_comments._43_introduce_assertion;
|
||||
|
||||
public class Customer {
|
||||
|
||||
private Double discountRate;
|
||||
|
||||
public double applyDiscount(double amount) {
|
||||
return (this.discountRate != null) ? amount - (this.discountRate * amount) : amount;
|
||||
}
|
||||
|
||||
public Double getDiscountRate() {
|
||||
return discountRate;
|
||||
}
|
||||
|
||||
public void setDiscountRate(Double discountRate) {
|
||||
assert discountRate != null && discountRate > 0;
|
||||
this.discountRate = discountRate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.example.refactoring._24_comments._43_introduce_assertion._before;
|
||||
|
||||
public class Customer {
|
||||
|
||||
private Double discountRate;
|
||||
|
||||
public double applyDiscount(double amount) {
|
||||
return (this.discountRate != null) ? amount - (this.discountRate * amount) : amount;
|
||||
}
|
||||
|
||||
public Double getDiscountRate() {
|
||||
return discountRate;
|
||||
}
|
||||
|
||||
public void setDiscountRate(Double discountRate) {
|
||||
this.discountRate = discountRate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.refactoring._24_comments._43_introduce_assertion;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class CustomerTest {
|
||||
|
||||
@Test
|
||||
void setDiscountRate() {
|
||||
Customer customer = new Customer();
|
||||
customer.setDiscountRate(-10d);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user