-
Notifications
You must be signed in to change notification settings - Fork 0
[#1] 대출 기간 객체 분리 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
package com.study.bookcafe.vo; | ||
|
||
import lombok.NonNull; | ||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
|
||
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; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Period period = (Period) o; | ||
return Objects.equals(from, period.from) && Objects.equals(to, period.to); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(from, to); | ||
} | ||
} |
This file contains hidden or 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)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
롬복을 쓰지 않았던가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
롬복으로 대체할 수 있는 어노테이션을 처음 알아서 적용했습니다 ㅎㅎ