Skip to content

Commit c02aedb

Browse files
committed
[java][booking][02_parameter_object] Introduce Discount parameter object
1 parent c17873b commit c02aedb

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-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
@@ -20,8 +20,7 @@ public Booking(
2020
DateRange bookingDateRange,
2121
Customer customer,
2222
BookingType bookingType,
23-
DiscountType discountType,
24-
DiscountValue discountValue,
23+
Discount discount,
2524
TaxType taxType,
2625
TaxValue taxValue
2726
) {
@@ -32,8 +31,8 @@ public Booking(
3231
this.customerName = customer.name();
3332
this.customerEmail = customer.emailAddress();
3433
this.bookingType = bookingType;
35-
this.discountType = discountType;
36-
this.discountValue = discountValue;
34+
this.discountType = discount.type();
35+
this.discountValue = discount.value();
3736
this.taxType = taxType;
3837
this.taxValue = taxValue;
3938
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package tv.codely.booking;
2+
3+
public final class Discount {
4+
private final DiscountType type;
5+
private final DiscountValue value;
6+
7+
public Discount(DiscountType type, DiscountValue value) {
8+
this.type = type;
9+
this.value = value;
10+
}
11+
12+
public DiscountType type() {
13+
return type;
14+
}
15+
16+
public DiscountValue value() {
17+
return value;
18+
}
19+
}

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
@@ -23,8 +23,7 @@ void get_the_correct_status_when_the_booking_has_not_started_yet() {
2323
new EmailAddress("perico.los.palotes@mail.com")
2424
),
2525
BookingType.VACATION,
26-
DiscountType.NONE,
27-
new DiscountValue(0),
26+
new Discount(DiscountType.NONE, new DiscountValue(0)),
2827
TaxType.NONE,
2928
new TaxValue(0)
3029
);
@@ -48,8 +47,7 @@ void get_the_correct_status_when_the_booking_is_currently_active() {
4847
new EmailAddress("perico.los.palotes@mail.com")
4948
),
5049
BookingType.VACATION,
51-
DiscountType.NONE,
52-
new DiscountValue(0),
50+
new Discount(DiscountType.NONE, new DiscountValue(0)),
5351
TaxType.NONE,
5452
new TaxValue(0)
5553
);
@@ -73,8 +71,7 @@ void get_the_correct_status_when_the_booking_is_finished() {
7371
new EmailAddress("perico.los.palotes@mail.com")
7472
),
7573
BookingType.VACATION,
76-
DiscountType.NONE,
77-
new DiscountValue(0),
74+
new Discount(DiscountType.NONE, new DiscountValue(0)),
7875
TaxType.NONE,
7976
new TaxValue(0)
8077
);

0 commit comments

Comments
 (0)