Skip to content

Commit 9b157a1

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

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public final class Booking {
1717

1818
public Booking(
1919
BookingId id,
20-
LocalDateTime startDate,
21-
LocalDateTime endDate,
20+
DateRange bookingDateRange,
2221
CustomerId customerId,
2322
CustomerName customerName,
2423
EmailAddress customerEmail,
@@ -29,8 +28,8 @@ public Booking(
2928
TaxValue taxValue
3029
) {
3130
this.id = id;
32-
this.startDate = startDate;
33-
this.endDate = endDate;
31+
this.startDate = bookingDateRange.startDate();
32+
this.endDate = bookingDateRange.endDate();
3433
this.customerId = customerId;
3534
this.customerName = customerName;
3635
this.customerEmail = customerEmail;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package tv.codely.booking;
2+
3+
import java.time.LocalDateTime;
4+
5+
public final class DateRange {
6+
private final LocalDateTime startDate;
7+
private final LocalDateTime endDate;
8+
9+
public DateRange(LocalDateTime startDate, LocalDateTime endDate) {
10+
this.startDate = startDate;
11+
this.endDate = endDate;
12+
}
13+
14+
public LocalDateTime startDate() {
15+
return startDate;
16+
}
17+
18+
public LocalDateTime endDate() {
19+
return endDate;
20+
}
21+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ void get_the_correct_status_when_the_booking_has_not_started_yet() {
1616

1717
var booking = new Booking(
1818
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
19-
bookingStartDate,
20-
bookingEndDate,
19+
new DateRange(bookingStartDate, bookingEndDate),
2120
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
2221
new CustomerName("Perico Los Palotes"),
2322
new EmailAddress("perico.los.palotes@mail.com"),
@@ -40,8 +39,7 @@ void get_the_correct_status_when_the_booking_is_currently_active() {
4039

4140
var booking = new Booking(
4241
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
43-
bookingStartDate,
44-
bookingEndDate,
42+
new DateRange(bookingStartDate, bookingEndDate),
4543
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
4644
new CustomerName("Perico Los Palotes"),
4745
new EmailAddress("perico.los.palotes@mail.com"),
@@ -64,8 +62,7 @@ void get_the_correct_status_when_the_booking_is_finished() {
6462

6563
var booking = new Booking(
6664
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
67-
bookingStartDate,
68-
bookingEndDate,
65+
new DateRange(bookingStartDate, bookingEndDate),
6966
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
7067
new CustomerName("Perico Los Palotes"),
7168
new EmailAddress("perico.los.palotes@mail.com"),

0 commit comments

Comments
 (0)