Skip to content

Commit

Permalink
변경된 파라미터 개수로 인해 객체로 변경 - #19
Browse files Browse the repository at this point in the history
  • Loading branch information
hou27 committed Jan 12, 2023
1 parent 5db59c7 commit 5dfcf0c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public class ExpiryDateCalculatorTest {
assertExpiryDate(LocalDate.of(2022, 3, 1), 10_000, LocalDate.of(2022, 4, 1));
}

private void assertExpiryDate(LocalDate billingDate, int payAmount, LocalDate expiryDate) {
ExpiryDateCalculator cal = new ExpiryDateCalculator();
LocalDate result = cal.calculateExpiryDate(billingDate, payAmount);
assertEquals(expiryDate, result);
}

@Test
void 납부일과_한달__일자가_같지_않음() {
assertExpiryDate(LocalDate.of(2019, 1, 31), 10_000, LocalDate.of(2019, 2, 28));
assertExpiryDate(LocalDate.of(2019, 5, 31), 10_000, LocalDate.of(2019, 6, 30));
assertExpiryDate(LocalDate.of(2020, 1, 31), 10_000, LocalDate.of(2020, 2, 29));
assertExpiryDate(LocalDate.of(2020, 5, 31), 10_000, LocalDate.of(2020, 6, 30));
}

private void assertExpiryDate(LocalDate billingDate, int payAmount, LocalDate expiryDate) {
ExpiryDateCalculator cal = new ExpiryDateCalculator();
LocalDate result = cal.calculateExpiryDate(billingDate, payAmount);
assertEquals(expiryDate, result);
}
}
46 changes: 46 additions & 0 deletions 김정호/src/test/java/com/hou27/chap03/PayData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.hou27.chap03;

import java.time.LocalDate;

public class PayData {
private LocalDate billingDate;
private int payAmount;

private PayData() {};

public PayData(LocalDate billingDate, int payAmount) {
this.billingDate = billingDate;
this.payAmount = payAmount;
}

public LocalDate getBillingDate() {
return billingDate;
}

public int getPayAmount() {
return payAmount;
}

/*
* billingDate와 payAmount를 설정하는 것을 쉽게 알 수 있도록
* builder pattern을 적용
*/
public static class Builder {
private PayData data = new PayData();

public Builder billingDate(LocalDate billingDate) {
data.billingDate = billingDate;
return this;
}

public Builder payAmount(int payAmount) {
data.payAmount = payAmount;
return this;
}

public PayData build() {
return data;
}
}

}

0 comments on commit 5dfcf0c

Please sign in to comment.