-
Notifications
You must be signed in to change notification settings - Fork 0
Test/테스트 코드 보완 #14
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
The head ref may contain hidden characters: "test/\uD14C\uC2A4\uD2B8-\uCF54\uB4DC-\uBCF4\uC644"
Test/테스트 코드 보완 #14
Changes from 5 commits
c440a1a
b51bf13
bcd549a
86cf420
7b8b117
d2a3a24
3f31001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package me.pinitnotification.domain.notification | ||
|
|
||
| import org.assertj.core.api.Assertions | ||
| import org.junit.jupiter.api.Test | ||
| import java.time.Clock | ||
| import java.time.LocalDateTime | ||
| import java.time.OffsetDateTime | ||
| import java.time.ZoneId | ||
| import java.time.ZoneOffset.UTC | ||
|
|
||
| internal class UpcomingScheduleNotificationTest { | ||
| val clock = Clock.fixed( | ||
| LocalDateTime.of( | ||
| 2026, | ||
| 1, | ||
| 1, | ||
| 0, | ||
| 0, | ||
| 0 | ||
| ).toInstant(UTC), ZoneId.systemDefault() | ||
| ) | ||
|
|
||
| @Test | ||
| fun updateScheduleStartTime() { | ||
| //given | ||
| val notification = getSampleUpcomingScheduleNotification() | ||
|
|
||
| //when | ||
| notification.updateScheduleStartTime("2024-06-01T10:00:00Z", "123-idempotency-key") | ||
|
|
||
| //then | ||
| Assertions.assertThat(notification.scheduleStartTime).isEqualTo("2024-06-01T10:00:00Z") | ||
| Assertions.assertThat(notification.idempotentKey).isEqualTo("123-idempotency-key") | ||
| } | ||
|
|
||
| @Test | ||
| fun isDue() { | ||
| //given | ||
| val notification = getSampleUpcomingScheduleNotification( | ||
| scheduleStartTime = "2024-06-01T10:00:00Z" | ||
| ) | ||
|
|
||
| //when | ||
| val isDue = notification.isDue(OffsetDateTime.now(clock)) | ||
|
|
||
| //then | ||
| Assertions.assertThat(isDue).isTrue() | ||
| } | ||
|
Comment on lines
+36
to
+48
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package me.pinitnotification.domain.notification | ||
|
|
||
| import org.junit.platform.commons.util.ReflectionUtils | ||
|
|
||
| fun getSampleUpcomingScheduleNotification( | ||
| id: Long = 1L, | ||
| ownerId: Long = 1L, | ||
| scheduleId: Long = 1L, | ||
| scheduleTitle: String = "sample", | ||
| scheduleStartTime: String = "2024-06-01T10:00:00Z", | ||
| idempotencyKey: String = "", | ||
| ): UpcomingScheduleNotification { | ||
| val sample = UpcomingScheduleNotification( | ||
| ownerId, | ||
| scheduleId, | ||
| scheduleTitle, | ||
| scheduleStartTime, | ||
| idempotencyKey | ||
| ) | ||
| ReflectionUtils.findFields( | ||
| UpcomingScheduleNotification::class.java, | ||
| { field -> field.name == "id" }, | ||
| ReflectionUtils.HierarchyTraversalMode.TOP_DOWN | ||
| ).forEach { field -> | ||
| field.isAccessible = true | ||
| field.set(sample, id) | ||
| } | ||
|
Comment on lines
+20
to
+27
|
||
| return sample | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||||||||||||||||||||||||||||||||||
| package me.pinitnotification.domain.push | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import org.assertj.core.api.Assertions | ||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.Test | ||||||||||||||||||||||||||||||||||||||
| import java.time.Clock | ||||||||||||||||||||||||||||||||||||||
| import java.time.LocalDateTime | ||||||||||||||||||||||||||||||||||||||
| import java.time.ZoneId | ||||||||||||||||||||||||||||||||||||||
| import java.time.ZoneOffset.UTC | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| internal class PushSubscriptionTest { | ||||||||||||||||||||||||||||||||||||||
| val clock = Clock.fixed( | ||||||||||||||||||||||||||||||||||||||
| LocalDateTime.of( | ||||||||||||||||||||||||||||||||||||||
| 2026, | ||||||||||||||||||||||||||||||||||||||
| 1, | ||||||||||||||||||||||||||||||||||||||
| 1, | ||||||||||||||||||||||||||||||||||||||
| 0, | ||||||||||||||||||||||||||||||||||||||
| 0, | ||||||||||||||||||||||||||||||||||||||
| 0 | ||||||||||||||||||||||||||||||||||||||
| ).toInstant(UTC), ZoneId.systemDefault() | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| import java.time.Clock | |
| import java.time.LocalDateTime | |
| import java.time.ZoneId | |
| import java.time.ZoneOffset.UTC | |
| internal class PushSubscriptionTest { | |
| val clock = Clock.fixed( | |
| LocalDateTime.of( | |
| 2026, | |
| 1, | |
| 1, | |
| 0, | |
| 0, | |
| 0 | |
| ).toInstant(UTC), ZoneId.systemDefault() | |
| ) | |
| internal class PushSubscriptionTest { |
Copilot
AI
Jan 16, 2026
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.
문제점: PushSubscription.updateToken() 메서드는 modifiedAt이 현재 시간보다 이후일 경우 토큰 업데이트를 건너뛰는 로직이 있지만, 이 테스트는 해당 조건 분기를 검증하지 않고 있습니다.
영향: 중요한 비즈니스 로직(시간 기반 조건부 업데이트)이 테스트되지 않아, 향후 코드 변경 시 버그가 발생할 수 있습니다.
수정 제안: modifiedAt이 미래 시간으로 설정된 경우 토큰이 업데이트되지 않는지 확인하는 추가 테스트 케이스를 작성하세요.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package me.pinitnotification.domain.push | ||
|
|
||
| import org.junit.platform.commons.util.ReflectionUtils | ||
| import java.time.Instant | ||
|
|
||
| fun getSamplePushSubscription( | ||
| id: Long = 1L, | ||
| memberId: Long = 1L, | ||
| deviceId: String = "sample-device-id", | ||
| token: String = "sample-token", | ||
| modifiedAt: Instant = Instant.EPOCH, | ||
| ): PushSubscription { | ||
| val sample = PushSubscription(memberId, deviceId, token) | ||
| ReflectionUtils.findFields( | ||
| PushSubscription::class.java, | ||
| { field -> field.name == "id" }, | ||
| ReflectionUtils.HierarchyTraversalMode.TOP_DOWN | ||
| ).forEach { field -> | ||
| field.isAccessible = true | ||
| field.set(sample, id) | ||
| } | ||
|
Comment on lines
+14
to
+21
|
||
| ReflectionUtils.findFields( | ||
| PushSubscription::class.java, | ||
| { field -> field.name == "modifiedAt" }, | ||
| ReflectionUtils.HierarchyTraversalMode.TOP_DOWN | ||
| ).forEach { field -> | ||
| field.isAccessible = true | ||
| field.set(sample, modifiedAt) | ||
| } | ||
|
Comment on lines
+22
to
+29
|
||
| return sample | ||
| } | ||
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.
문제점: 테스트가
updateScheduleStartTime메서드를 호출하지만, 실제로는 두 개의 필드(scheduleStartTime과idempotentKey)를 함께 업데이트하고 있습니다. 테스트 메서드명이 메서드의 전체 동작을 충분히 설명하지 못합니다.영향: 테스트의 의도가 명확하지 않아 향후 유지보수 시 혼란을 줄 수 있습니다.
수정 제안: 테스트 메서드명을
updateScheduleStartTimeAndIdempotencyKey처럼 더 구체적으로 변경하거나, 각 필드 업데이트를 개별적으로 테스트하는 것을 고려하세요.