-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from f-lab-edu/feature/1
[#1] 대출 기간 객체 분리
- Loading branch information
Showing
4 changed files
with
80 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.study.bookcafe.vo; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.NonNull; | ||
import java.time.LocalDateTime; | ||
|
||
@EqualsAndHashCode | ||
public class Period { | ||
/* | ||
- 대출 일자가 반납 일자보다 더 이전인 것을 보장할 책임 | ||
- 대출 기간(대출 일자 ~ 반납 일자)을 생성할 책임 | ||
- 연장 여부에 따라 반납 일자가 변경 | ||
- 기본: 1주, 연장 시: 1주 추가, 총 2주 | ||
*/ | ||
|
||
private final LocalDateTime from; // 대출 일자 | ||
private final LocalDateTime to; // 반납 일자 | ||
|
||
public Period(@NonNull LocalDateTime from) { | ||
this.from = from; | ||
this.to = this.from.plusWeeks(1); | ||
} | ||
|
||
public Period(@NonNull LocalDateTime from, @NonNull LocalDateTime to) { | ||
if(from.isAfter(to)) throw new IllegalArgumentException("반납 일자는 대출 일자보다 이후여야 합니다."); | ||
|
||
this.from = from; | ||
this.to = to; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.study.bookcafe.borrow; | ||
|
||
import com.study.bookcafe.vo.Period; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import java.time.LocalDateTime; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class PeriodTest { | ||
|
||
LocalDateTime date1 = LocalDateTime.of(2024, 12, 7, 12, 0, 0); | ||
LocalDateTime date2 = LocalDateTime.of(2024, 12, 8, 12, 0, 0); | ||
|
||
@Test | ||
@DisplayName("반납일자는 대출일자보다 이후여야 한다.") | ||
public void createPeriodTest() { | ||
Period period1 = new Period(date1, date2); | ||
Period period2 = new Period(date2, date2); | ||
|
||
assertThat(period1).isNotNull(); | ||
assertThat(period2).isNotNull(); | ||
} | ||
|
||
@Test | ||
@DisplayName("반납일자가 대출일자보다 이전이거나 반납일자 또는 대출일자가 null이면 예외가 발생한다.") | ||
public void createPeriodExceptionTest() { | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> new Period(date2, date1)); | ||
Assertions.assertThrows(NullPointerException.class, () -> new Period(null, null)); | ||
} | ||
} |