Conversation
WalkthroughA new enum, Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RunningRecord
participant DefaultTitle
Client->>RunningRecord: Create instance (title not provided)
RunningRecord->>DefaultTitle: fromTime(startedAt)
DefaultTitle-->>RunningRecord: Return appropriate title
RunningRecord-->>Client: Instance with default title set
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
src/main/java/org/runimo/runimo/records/domain/DefaultTitle.java (1)
6-31: Well-structured enum implementation for default titles based on time of dayThis is a clean implementation of an enum that provides default Korean titles based on the time of day. The time ranges are properly defined without gaps or overlaps.
Consider adding JavaDoc comments to document the purpose of this enum and its methods:
@Getter +/** + * Provides default titles for running records based on the time of day. + * The titles are in Korean and correspond to morning, afternoon, night and midnight runs. + */ public enum DefaultTitle { MORNING("개운한 아침런"), AFTERNOON("활기찬 오후런"), NIGHT("두근두근 저녁런"), MIDNIGHT("고요한 심야런"); private final String title; DefaultTitle(String title) { this.title = title; } + /** + * Determines the appropriate default title based on the time of day. + * @param time The time to evaluate + * @return The corresponding DefaultTitle enum constant + */ public static DefaultTitle fromTime(LocalDateTime time) { + if (time == null) { + throw new IllegalArgumentException("Time cannot be null"); + } int hour = time.getHour(); if (hour < 6) { return MIDNIGHT; } else if (hour < 12) { return MORNING; } else if (hour < 18) { return AFTERNOON; } else { return NIGHT; } } }src/test/java/org/runimo/runimo/records/domain/RunningRecordTest.java (3)
14-26: Effective test for default title assignmentThis test verifies that a default title is assigned when one is not provided, which is the primary functionality being added.
Consider enhancing this test to verify the specific title that was set, not just that it's non-null:
@Test void 제목을_입력하지_않으면_기본_제목_설정() { + // Given RunningRecord runningRecordWithoutTitle = RunningRecord.builder() .userId(1L) .startedAt(LocalDateTime.now()) .endAt(LocalDateTime.now().plusHours(1)) .isRewarded(false) .totalDistance(new Distance(1000L)) .pacePerKm(null) .build(); + // Then assertNotNull(runningRecordWithoutTitle.getTitle()); + + // Verify the title matches one of the expected default titles based on time + LocalDateTime startTime = runningRecordWithoutTitle.getStartedAt(); + String expectedTitle = DefaultTitle.fromTime(startTime).getTitle(); + assertEquals(expectedTitle, runningRecordWithoutTitle.getTitle()); }
29-51: Well-structured parameterized test for time-based default titlesThis test effectively verifies that different default titles are set based on the time of day, covering all four time categories. The test data is clear and comprehensive.
Consider these small improvements for better test structure:
@ParameterizedTest(name = "{0}시에 달리면 {1} 제목이 설정됨") @CsvSource({ "2020-01-01T07:00:00, 개운한 아침런", "2020-01-01T13:00:00, 활기찬 오후런", "2020-01-01T19:00:00, 두근두근 저녁런", "2020-01-01T01:00:00, 고요한 심야런" }) void 기본_제목_설정시_시간에_따라_제목이_달라진다(String dateTimeStr, String expectedTitle) { // given LocalDateTime runAt = LocalDateTime.parse(dateTimeStr); + // when RunningRecord runningRecordWithoutTitle = RunningRecord.builder() .userId(1L) .startedAt(runAt) .endAt(runAt.plusHours(1)) .isRewarded(false) .totalDistance(new Distance(1000L)) .pacePerKm(null) .build(); // then assertEquals(expectedTitle, runningRecordWithoutTitle.getTitle()); }
12-52: Consider adding a test to verify that user-provided titles are preservedThe current tests verify that default titles are set when none is provided, but there's no test to verify that explicitly provided titles are preserved.
Add a test to verify that user-provided titles are not overridden:
@Test void 제목을_입력하면_기본_제목으로_변경되지_않음() { // Given String userProvidedTitle = "My Custom Title"; // When RunningRecord runningRecord = RunningRecord.builder() .userId(1L) .title(userProvidedTitle) .startedAt(LocalDateTime.now()) .endAt(LocalDateTime.now().plusHours(1)) .isRewarded(false) .totalDistance(new Distance(1000L)) .pacePerKm(null) .build(); // Then assertEquals(userProvidedTitle, runningRecord.getTitle()); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/org/runimo/runimo/records/domain/DefaultTitle.java(1 hunks)src/main/java/org/runimo/runimo/records/domain/RunningRecord.java(2 hunks)src/test/java/org/runimo/runimo/records/domain/RunningRecordTest.java(1 hunks)
🔇 Additional comments (1)
src/main/java/org/runimo/runimo/records/domain/RunningRecord.java (1)
58-58: Good placement of default title setting logicThe call to
setTitleIfNull()is properly placed at the end of the constructor, ensuring all necessary fields are initialized before using them.
작업 내역
사용자가 제목을 입력하지 않으면 시간대에 따라 기본 제목을 설정하는 기능 구현
DefaultTitleEnum으로 정의테스트코드 작성
Summary by CodeRabbit
New Features
Tests