Skip to content

Commit c17873b

Browse files
committed
[java][booking][02_parameter_object] Introduce Customer parameter object
1 parent 9b157a1 commit c17873b

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

examples/java/java-booking-02_introduce_parameter_object/src/main/java/tv/codely/booking/Booking.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ public final class Booking {
1818
public Booking(
1919
BookingId id,
2020
DateRange bookingDateRange,
21-
CustomerId customerId,
22-
CustomerName customerName,
23-
EmailAddress customerEmail,
21+
Customer customer,
2422
BookingType bookingType,
2523
DiscountType discountType,
2624
DiscountValue discountValue,
@@ -30,9 +28,9 @@ public Booking(
3028
this.id = id;
3129
this.startDate = bookingDateRange.startDate();
3230
this.endDate = bookingDateRange.endDate();
33-
this.customerId = customerId;
34-
this.customerName = customerName;
35-
this.customerEmail = customerEmail;
31+
this.customerId = customer.id();
32+
this.customerName = customer.name();
33+
this.customerEmail = customer.emailAddress();
3634
this.bookingType = bookingType;
3735
this.discountType = discountType;
3836
this.discountValue = discountValue;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package tv.codely.booking;
2+
3+
public final class Customer {
4+
private final CustomerId id;
5+
private final CustomerName name;
6+
private final EmailAddress emailAddress;
7+
8+
public Customer(CustomerId id, CustomerName name, EmailAddress emailAddress) {
9+
this.id = id;
10+
this.name = name;
11+
this.emailAddress = emailAddress;
12+
}
13+
14+
public CustomerId id() {
15+
return id;
16+
}
17+
18+
public CustomerName name() {
19+
return name;
20+
}
21+
22+
public EmailAddress emailAddress() {
23+
return emailAddress;
24+
}
25+
}

examples/java/java-booking-02_introduce_parameter_object/src/test/java/tv/codely/booking/BookingShould.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ void get_the_correct_status_when_the_booking_has_not_started_yet() {
1717
var booking = new Booking(
1818
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
1919
new DateRange(bookingStartDate, bookingEndDate),
20-
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
21-
new CustomerName("Perico Los Palotes"),
22-
new EmailAddress("perico.los.palotes@mail.com"),
20+
new Customer(
21+
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
22+
new CustomerName("Perico Los Palotes"),
23+
new EmailAddress("perico.los.palotes@mail.com")
24+
),
2325
BookingType.VACATION,
2426
DiscountType.NONE,
2527
new DiscountValue(0),
@@ -40,9 +42,11 @@ void get_the_correct_status_when_the_booking_is_currently_active() {
4042
var booking = new Booking(
4143
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
4244
new DateRange(bookingStartDate, bookingEndDate),
43-
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
44-
new CustomerName("Perico Los Palotes"),
45-
new EmailAddress("perico.los.palotes@mail.com"),
45+
new Customer(
46+
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
47+
new CustomerName("Perico Los Palotes"),
48+
new EmailAddress("perico.los.palotes@mail.com")
49+
),
4650
BookingType.VACATION,
4751
DiscountType.NONE,
4852
new DiscountValue(0),
@@ -63,9 +67,11 @@ void get_the_correct_status_when_the_booking_is_finished() {
6367
var booking = new Booking(
6468
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
6569
new DateRange(bookingStartDate, bookingEndDate),
66-
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
67-
new CustomerName("Perico Los Palotes"),
68-
new EmailAddress("perico.los.palotes@mail.com"),
70+
new Customer(
71+
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
72+
new CustomerName("Perico Los Palotes"),
73+
new EmailAddress("perico.los.palotes@mail.com")
74+
),
6975
BookingType.VACATION,
7076
DiscountType.NONE,
7177
new DiscountValue(0),

0 commit comments

Comments
 (0)