9. Supported By:
PRACTICE
BENTO
public class Customer {
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
10. Supported By:
PRACTICE
BENTO
public class CostumerTest {
@Test
public void should_always_have_an_email() {
Customer customer = new Customer();
assertEquals(customer.getEmail(), "andi.pangeran@jtravl.com");
}
}
TEST FAIL
11. Supported By:
PRACTICE
BENTO
public class CostumerTest {
@Test
public void should_always_have_an_email() {
Customer customer = new Customer();
customer.setEmail("andi.pangeran@jtravl.com");
assertEquals(customer.getEmail(), "andi.pangeran@jtravl.com");
}
}
TEST PASSED
13. Supported By:
PRACTICE
BENTO
public class CostumerTest {
@Test
public void should_always_have_an_email() {
Customer customer = new Customer("andi.pangeran@jtravl.com");
assertEquals(customer.getEmail(), "andi.pangeran@jtravl.com");
}
}
TEST PASSED
15. Supported By:
JOKO
PRACTICE
“later prospective customer can be
upgraded to paying customer“
“Paying customer must have phone
number”
“we have two type of customer,
prospective and paying customer.”
16. Supported By:
PRACTICE
BENTO
public class ProspectiveCustomer extends Customer {
/* other attribute */
}
public class PayingCustomer extends Customer {
/* other attribute */
private String phone;
public PayingCustomer(String email, String phone) {
super(email);
this.phone = phone;
}
}
17. Supported By:
PRACTICE
BENTO
@Test
public void upgraded_prospective_paying() {
ProspectiveCustomer pcustomer = new
ProspectiveCustomer("andi.pangeran@jtravl.com");
assertEquals(pcustomer.getEmail(), "andi.pangeran@jtravl.com");
PayingCustomer payCustomer =
new PayingCustomer(pcustomer.getName(), “0852xxx”);
assertEquals(payCustomer.getEmail(), "andi.pangeran@jtravl.com");
assertEquals(payCustomer.getPhone(), " 0852xxx");
}
TEST FAIL
18. Supported By:
PRACTICE
BENTO
@Test
public void upgraded_prospective_paying() {
ProspectiveCustomer pcustomer = new
ProspectiveCustomer("andi.pangeran@jtravl.com");
assertEquals(pcustomer.getEmail(), "andi.pangeran@jtravl.com");
PayingCustomer payCustomer =
new PayingCustomer(pcustomer.getEmail(), “0852xxx”);
assertEquals(payCustomer.getEmail(), "andi.pangeran@jtravl.com");
assertEquals(payCustomer.getPhone(), " 0852xxx");
}
TEST PASSED
19. Supported By:
PRACTICE
BENTO
public class ProspectiveCustomer extends Customer {
/* other attribute */
public PayingCustomer upgradeToPayingCustomer(String phone) {
return new PayingCustomer(this.email, phone);
}
}
public class PayingCustomer extends Customer {
/* other attribute */
private String phone;
public PayingCustomer(String email, String phone) {
super(email);
this.phone = phone;
}
}
20. Supported By:
PRACTICE
BENTO
@Test
public void upgraded_prospective_paying() {
ProspectiveCustomer pcustomer = new
ProspectiveCustomer("andi.pangeran@jtravl.com");
assertEquals(pcustomer.getEmail(), "andi.pangeran@jtravl.com");
PayingCustomer payCustomer = pcostumer.upgradeToPaying(“0852xxx”);
assertEquals(payCustomer.getEmail(), "andi.pangeran@jtravl.com");
assertEquals(payCustomer.getPhone(), " 0852xxx");
}
TEST PASSED
22. Supported By:
PRACTICE
BENTO
@Test
public void upgraded_prospective_paying() {
PayingCustomer payCustomer =
new PayingCustomer(“test@mail.com", “badphonenumber”);
exception.expect(IllegalArgumentException.class);
}
TEST FAIL
23. Supported By:
PRACTICE
BENTO
public class PayingCustomer extends Customer {
/* other attribute */
private String phone;
public PayingCustomer(String email, String phone) {
super(email);
if (/* validation stuff of phone*/ ) {
throw new IllegalArgumentException();
}
this.phone = phone;
}
}
TEST PASSED
24. Supported By:
PRACTICE
BENTO
public class PayingCustomer extends Customer {
/* other attribute */
private String phone;
public PayingCustomer(String email, String phone) {
super(email);
if (/* validation stuff of phone*/ ) {
throw new IllegalArgumentException();
}
this.phone = phone;
}
}
TEST PASSED
27. Supported By:
PRACTICE
BENTO
public class PhoneNumber {
private final String phone;
public PhoneNumber(String phone) {
if (/* validation stuff of phone*/ ) {
throw new IllegalArgumentException();
}
this.phone = phone;
}
public String getPhone() {
{
return this.phone;
}
}
28. Supported By:
PRACTICE
BENTO
public class PayingCustomer extends Customer {
/* other attribute */
private PhoneNumber phone;
public PayingCustomer(String email, PhoneNumber phone) {
super(email);
this.phone = phone;
}
}
TEST PASSED
29. Supported By:
PRACTICE
BENTO
@Test
public void upgraded_prospective_paying() {
PayingCustomer payCustomer =
new PayingCustomer(“test@mail.com", new
PhoneNumber(“badphonenumber”));
exception.expect(IllegalArgumentException.class);
}
TEST PASSED
32. Supported By:
Service.create
BENTO
Order order = new Order();
order.setCustomer(customer);
order.setProducts(products);
order.setStatus(PAYMENTSTATUS.UNPAID);
order.setPaidAmount(500);
order.setPaidCurrency(CURRENCY.IDR);
order.setStatus(PAYMENTSTATUS.PAID);
PRACTICE
Service.pay
33. Supported By:
Service.create
BENTO
Order order = new Order();
order.setCustomer(customer);
order.setProducts(products);
order.setStatus(new PaymentStatus(PAYMENTSTATUS.UNPAID));
order.setPaidAmount(500);
order.setPaidCurrency(CURRENCY.IDR);
order.setStatus(new PaymentStatus(PAYMENTSTATUS.PAID));
PRACTICE
Service.pay
34. Supported By:
Service.create
BENTO
Order order = new Order();
order.setCustomer(customer);
order.setProducts(products);
order.setStatus(new PaymentStatus(PAYMENTSTATUS.UNPAID));
order.setPaidMonetary(new Money(500, CURRENCY.IDR));
order.setStatus(new PaymentStatus(PAYMENTSTATUS.PAID));
PRACTICE
Service.pay
35. Supported By:
Service.create
BENTO
Order order = new Order(customer, products);
//set payment status in order constructor
order.setPaidMonetary(new Money(500, CURRENCY.IDR));
order.setStatus(new PaymentStatus(PAYMENTSTATUS.PAID));
PRACTICE
Service.pay
36. Supported By:
Service.create
BENTO
Order order = new Order(customer, products);
//set payment status in order constructor
order.pay (new Money(500, CURRENCY.IDR));
//set payment status in pay procedure
PRACTICE
Service.pay
45. Supported By:
BENTO
public class CustomerWith3OrdersIsPremium implement
CustomerIsPremium {}
public class CustomerWith500kPremium implement
CustomerIsPremium {}
public class CustomerWithSpecialRequiredmentPremium
implement CustomerIsPremium {}
PRACTICE
Specification Interface
public interface CustomerIsPremium extends
Specification<Customer> {
boolean isSatisfiedBy(Customer cust);
}
46. Supported By:
BENTO
PRACTICE
public class SpecialOfferSender {
private CustomerIsPremium premiumSpec
public SpecialOfferSende(CustomerIsPremium premiumSpec) {
this.orderRepository = orderRepository;
}
public void sendOffersTo(Customer customer) {
if (this.premiumSpec.isSatisfiedBy(customer)) {
//send offers
}
}
}
55. Supported By:
SUMMARY
Protect your invariants
Use object as consistency boundaries
Encapulate state and behavior with value object
Encapulate Operations
Use specification pattern
Use predicate pattern