-
Notifications
You must be signed in to change notification settings - Fork 1
[✨feat] InternshipWorkingPeriod 구현 #57
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
+87
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fb967e7
feat(InternshipErrorCode) : 근무 기간 예외 코드 추가
jsoonworld fac2317
feat(InternshipWorkingPeriod) : 인턴십 근무 기간 VO 구현
jsoonworld 6dc7559
test(InternshipWorkingPeriodTest) : InternshipWorkingPeriod 단위 테스트 추가
jsoonworld b84c149
refactor(InternshipWorkingPeriod) : Kotlin 컨벤션에 맞춰 선언 순서 정렬
jsoonworld b9e464a
refactor(InternshipWorkingPeriod) : 최소 근무 기간 기준을 상수로 추출하여 의미 명확화
jsoonworld 97eaa44
chore(InternshipWorkingPeriod) : ktlint format 적용
jsoonworld 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
32 changes: 32 additions & 0 deletions
32
...kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/InternshipWorkingPeriod.kt
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.terning.server.kotlin.domain.internshipAnnouncement | ||
|
||
import jakarta.persistence.Embeddable | ||
|
||
@Embeddable | ||
class InternshipWorkingPeriod private constructor( | ||
val months: Int, | ||
) { | ||
init { | ||
validatePositive(months) | ||
} | ||
|
||
fun toKoreanPeriod(): String = "${months}개월" | ||
|
||
override fun equals(other: Any?): Boolean = this === other || (other is InternshipWorkingPeriod && months == other.months) | ||
|
||
override fun hashCode(): Int = months | ||
|
||
override fun toString(): String = toKoreanPeriod() | ||
|
||
companion object { | ||
private const val MINIMUM_MONTHS = 1 | ||
|
||
fun from(months: Int): InternshipWorkingPeriod = InternshipWorkingPeriod(months) | ||
|
||
private fun validatePositive(months: Int) { | ||
if (months < MINIMUM_MONTHS) { | ||
throw InternshipException(InternshipErrorCode.INVALID_WORKING_PERIOD) | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...in/com/terning/server/kotlin/domain/internshipAnnouncement/InternshipWorkingPeriodTest.kt
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,54 @@ | ||
package com.terning.server.kotlin.domain.internshipAnnouncement | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class InternshipWorkingPeriodTest { | ||
@Nested | ||
@DisplayName("InternshipWorkingPeriod.from 메서드는") | ||
inner class From { | ||
@Test | ||
@DisplayName("유효한 개월 수를 입력하면 객체를 생성한다") | ||
fun `create instance when valid months given`() { | ||
// given | ||
val months = 3 | ||
|
||
// when | ||
val period = InternshipWorkingPeriod.from(months) | ||
|
||
// then | ||
assertThat(period.months).isEqualTo(months) | ||
} | ||
|
||
@Test | ||
@DisplayName("0 이하의 개월 수를 입력하면 예외를 던진다") | ||
fun `throw exception when months is zero or negative`() { | ||
val exception = | ||
assertThrows<InternshipException> { | ||
InternshipWorkingPeriod.from(0) | ||
} | ||
|
||
assertThat(exception.errorCode).isEqualTo(InternshipErrorCode.INVALID_WORKING_PERIOD) | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("toKoreanPeriod 메서드는") | ||
inner class ToKoreanPeriod { | ||
@Test | ||
@DisplayName("개월 수를 'N개월' 형태의 문자열로 반환한다") | ||
fun `return correct korean period string`() { | ||
// given | ||
val period = InternshipWorkingPeriod.from(6) | ||
|
||
// when | ||
val result = period.toKoreanPeriod() | ||
|
||
// then | ||
assertThat(result).isEqualTo("6개월") | ||
} | ||
} | ||
} |
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.
단순 궁금증에 여쭤봅니다!
아래 테스트 코드들에서는 그냥 정수를 넣어주고 있는데 해당 테스트 코드 케이스에서는
month
라고 변수화를 해주고 있어서 혹시 장순님의 기준이 있는 건지 궁금했어요..!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.
좋은 질문 감사합니다! 🙏
사실 이 부분은 명확한 기준이 있다기보다는,
"해당 값에 의미를 부여하고 싶을 때는 변수로 선언하고, 그렇지 않을 경우에는 인라인으로 작성하는 편"인데요,
이 테스트에서는 "유효한 month를 넘겼을 때"라는 케이스 자체가 핵심이라
months라는 이름으로 문맥을 명확히 드러내고 싶어서 변수화했던 것 같아요!
반대로 다른 테스트들에서는 특별한 의미 없이 단순히 값을 넘기기만 해서 인라인으로 처리했던 것 같습니다 😅
일관성 측면에서는 통일하는 게 더 좋을 것 같기도 해서,
이번 기회에 기준을 한 번 더 다듬어보는 계기로 삼아보겠습니다! 질문 감사합니다 🙇♂️✨